繁体   English   中英

angularjs指令内的链接功能不起作用

[英]link function inside angularjs directive not working

在这里有一个js小提琴

指令既不呈现,也不调用该指令的链接函数。

代号:JS

(function() {
    var app = angular.module("directives", []);

    app.directive("mySample", function() {
        return {
            restric: "E",
            replace: true,
            template: "<div>sample directive</div>",
            link: function(scope, elem, attrs) {
                console.log(elem);
            }
        };
    });
}());

HTML:

<body ng-app="directives">
      <my-sample></my-sample>
</body>

您的指令具有restric属性,应在该位置进行restrict (缺少最后的't')。

暂无
暂无

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

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