当我点击我的HTML img时,ng-click不起作用。我不明白为什么。此错误发生在 masonryPictureView.html
中主页 - 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");
}
}
}
}])
答案 0 :(得分:0)
“projectdescription.pictures”来自哪里?,它是一个数组吗?它可能是空的吗?在控制台中查找错误。我建议您使用命名空间而不是ng来获取自定义指令或属性。我做了plunker演示,无论何时点击图像,都会触发测试方法。
您可能错过了ngMasonry指令中的ng-transclude占位符?
template: '<div class="masonry"><ng-transclude></ng-transclude></div>',