angular.js - `ng-bind-html`中的`ng-click`指令不生效
習慣沉默
習慣沉默 2017-05-15 16:52:04
0
2
627

js代码如下:

$scope.uploadInfo = $sce.trustAsHtml('上传成功!<a ng-click="'+
                        "quitTo('customer')"+
                        '">点击</a>跳转到客户列表界面');
                        //$scope.$apply();

html代码如下:

<p class="modal-content">
    <p class="modal-body" ng-bind-html="uploadInfo">
    </p>
</p>

在浏览器中看到的dom结构如下:


点击图中文字链接没有任何响应,在“quitTo()”函数中设断点发现没有执行到。
怎么才能让这里生效呢?我试了$scope.$apply(),还试了$compile(),发现都没有用。

習慣沉默
習慣沉默

reply all(2)
世界只因有你

If you have other methods or can explain its principle in detail, I hope you can share it with me

Although I solved this problem by myself, I don’t feel I understand it very well. Used

var uploadInfo = '上传成功!<a ng-click="'+
                        "quitTo('customer')"+
                        '">点击</a>跳转到客户列表界面';
var ele = $compile(uploadInfo)($scope);
angular.element('.modal-body').append(ele);

It’s no useng-bind-html$sce.trustAsHtml().

刘奇

Compile is required for any instruction to take effect. Angular does this step for you when the app is started, but the HTML you insert has not gone through the compile step, so you can compile it manually. You can write the instructions yourself before, dynamically I have encountered similar situations when inserting elements, please continue to communicate.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template