欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

javascript - angular自定义指令如何写

程序员文章站 2022-04-12 10:16:09
...
现在我有这样三段类似的代码

       {{planStatuse.name}}

                {{_appType.name}}

                {{centerPage.name}}


我要把这三块代码写成一个自定义指令 ,但是以上代码有的有事件,有的没有事件,而且事件不一样,该如何写?

var eInput= angular.module("eInput", []);
eInput.directive('eInput',function(){

return {
    restrict: "A",
    template:' 
'+ ' '+ '{{inputList.name}}'+ '
', replace:true, scope:{ inputListes:'=' } }

});

回复内容:

现在我有这样三段类似的代码

       {{planStatuse.name}}

                {{_appType.name}}

                {{centerPage.name}}


我要把这三块代码写成一个自定义指令 ,但是以上代码有的有事件,有的没有事件,而且事件不一样,该如何写?

var eInput= angular.module("eInput", []);
eInput.directive('eInput',function(){

return {
    restrict: "A",
    template:' 
'+ ' '+ '{{inputList.name}}'+ '
', replace:true, scope:{ inputListes:'=' } }

});

你确认一下你每个要执行的函数是否都在controller作用域里