简体   繁体   English

AngularJs ng-click无效指令

[英]AngularJs ng-click not working directive

When I click on my HTML img, ng-click doesn't work. 当我单击HTML img时,ng-click不起作用。 I don't understand why. 我不明白为什么。 This error happens in masonryPictureView.html 此错误发生在masonryPictureView.html中

Main page - home.html 主页-home.html

<ng-masonry>
  <ng-picture ng-items="projectdescription.pictures"></ng-picture>
</ng-masonry>

Template of directive ngPicture - masonryPictureView.html 指令ngPicture的模板-masonryPictureView.html

<ul class="grille">
 <li ng-repeat="item in ngItems">
  <img ng-click="test()" src="{{item.img}}"/>      <------ NG-CLICK
 </li>
</ul>

Directive in home.html 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");
            }
        }
    }
}])

Where does "projectdescription.pictures" come from?, Is it an array? “ projectdescription.pictures”从哪里来?是数组吗? Could it be empty?. 它可以是空的吗? Look in the console for errors. 在控制台中查找错误。 I recommend you that you use your namespace instead of ng for your custom directives or attributes. 我建议您为自定义指令或属性使用名称空间而不是ng。 I made a plunker demostrating that anytime an image is clicked the test method is fired. 我做出了一个笨拙的决定 ,即只要单击图像,就会触发测试方法。

It is possible that you missed the ng-transclude placeholder on the ngMasonry directive? 您是否有可能错过了ngMasonry指令上的ng-transclude占位符?

 template: '<div class="masonry"><ng-transclude></ng-transclude></div>',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM