当我点击我的HTML img时,ng-click不起作用。我不明白为什么。在发生这个错误masonryPictureView.htmlAngularJs ng-click不工作指令
主页 - home.html的
<ng-masonry>
<ng-picture ng-items="projectdescription.pictures"></ng-picture>
</ng-masonry>
模板指令ngPicture的 - masonryPictureView.html
<ul class="grille">
<li ng-repeat="item in ngItems">
<img ng-click="test()" src="{{item.img}}"/> <------ NG-CLICK
</li>
</ul>
指令在home.html的
app.directive('ngMasonry', [function() {
return {
restrict: 'E',
scope: {},
transclude: true,
templateUrl: "shared/masonry/masonryView.html",
controller: function ($scope) {
xxxxxxxxx......
},
}
}])
app.directive('ngPicture', ['$modal', '$log', function ($modal, $log) {
return {
require: "^ngMasonry",
restrict: 'E',
scope: {
ngItems: '=ngItems'
},
templateUrl: "shared/masonry/masonryPictureView.html",
link: function (scope, element, attrs, ngMasonryCtrl) {
ngMasonryCtrl.setPictures(scope.ngItems);
},
controller: function ($scope) {
$scope.test = function() < -- -- - function call in NG - CLICK {
console.log("toto");
}
}
}
}])
您应该使用带'ngclick'的定位点并包装图像。 –
这个SO帖子可能有帮助:[访问ng中单击自定义指令](http://stackoverflow.com/questions/24363217/angularjs-accessing-ng-click-in-custom-directive) –
嘿快问题,在控制台中是否有任何错误?其次,在第一个指令的控制器末尾加上这个额外的逗号'',是不是引起任何问题?第三,你可以通过在'$ scope.test'之上放置一个'console.log'来检查它是否到达'second directive's controller:'函数,最后,你需要'restrict:EA' directive'? –