當我點擊我的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'? –