angular.js - angular 自定义一个独立作用域指令, 在页面同时使用多次 ,数据全部一样的
滿天的星座
滿天的星座 2017-05-15 17:05:11
0
3
601

如题

指令代码如下

app.directive("info",[function(){
    return {
        restrict:'AE',
        scope:{},
        templateUrl:'views/finance/info.html',
        link:function($scope,element,attrs){
        }
    }
}])

html页面代码

<p info id=id1></p>
<p info id=id2></p>

这两个指令渲染完成后数据会都变成id=id2的
请问是什么原因

滿天的星座
滿天的星座

reply all(3)
左手右手慢动作

id1, id2 are the ids of the data, use this id to retrieve the data;

I found the reason myself. It’s because I used the id to distinguish the form. There is a form in views/finance/info.html. When using multiple same instructions, the id is not unique; o(╯□╰)o

Thanks to the two people above for their answers.

伊谢尔伦

I would like to ask, can id1 and id2 be added without ""? (This is a genuine question, not slander)

Peter_Zhu

There is nothing wrong with it from the code point of view. I don’t know how you use this command. There is too little code posted. And how did you determine that the data became id=id2?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template