Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个角度指令,它是一个自定义属性,可能包含如下值:
<div my-directive="myVal"></div>
如何从指令的链接函数中读取 myVal(作为字符串)?
传递的值位于作为第三个参数传递给链接函数的属性对象上。它位于与指令名称匹配的属性下。
app.directive('myDirective', function() { return { restrict: 'A', link: function(scope, elem, attr) { //read the passed value alert(attr.myDirective); } } });