0
我无法从通过ajax加载的某些内容中触发点击事件。没有看到从下面的代码或者执行console.log:Ajax加载元素上的Angularjs ng-click事件未触发
myApp.controller("MainController", function($scope, $http, $sce){
$scope.showModal = false;
$scope.openModal = function(name){
$scope.showModal = true;
$http({
method : 'GET',
url : '/template/fetch?name=' + name
}).success(function(modalHtml){
$scope.modalHtml = $sce.trustAsHtml(modalHtml);
$scope.closeModal = function(){
console.log("test 2");
};
});
};
$scope.closeModal = function(){
console.log("test 1");
};
});
这里是通过AJAX加载HTML:
<div class="modal">
<div class="modal-cover">
</div>
<div class="modal-container">
<div class="modal-close" ng-click="closeModal()"></div>
<div class="modal-content-container" ng-bind-html="modalContent">
</div>
</div>
</div>
谢谢!
的HTML通过ajax加载不会像你会通过jQuery那样工作。你会想要写一个指令或者做一些ngInclude,它有你的模态的html。 – lucuma