在Link函数AngularJS中设置属性

时间:2016-10-03 15:53:29

标签: angularjs angularjs-directive

我想知道在创建自定义指令时在链接函数中设置属性的最佳方法是什么。我们有两个选择:

1

function Link(scope, element, attrs, ctrls) {
  element[0].setAttribute("attName","attValue");
}

2

function Link(scope, element, attrs, ctrls) {
  attrs.$set("attName","attValue");
}

两种方式似乎都在元素上设置属性就好了。有人可以告诉我他们是否达到了相同的结果?有没有需要注意的警告?感谢..

0 个答案:

没有答案