admin管理员组文章数量:1330679
I was going through the process of creating a directive. Having gone through a few ups and downs I got through creating the directive ( widget ) and was finalizing the various attributes the directive will take.
I used the various options available like attribute, bind, evaluate, expression etc..
What I figured was that if you want to create a generic ponent, you can never tell how people will pass values to the the ponent.
Here is an illustration...
You are creating a new element ponent.. say
<hello name="__ARGUMENT__"></hello>
The name attribute for hello is the only variable in it. If you give it out to the public... these are the possible scenarios with which people may use this ponent.
case 1 :
<hello name="angular"></hello>
case 2 :
<hello name="{{name}}"></hello>
case 3 :
<div ng-repeat="name in names">
<hello name="name"></hello>
</div>
Now.. for different scenarios.. I have e to understand the various options provided. I cant think of a single scenario where you would ever want the 'attribute' since its a simple direct substitution of values from ponent to the template..
In your directive definition if you had defined the name as 'evaluate' instead of 'attribute'
if attribute :
<hello name="angular"></hello>
if evaluate :
<hello name="'angular'"></hello>
note the extra single quotes..
So as far as I can tell evaluate covers what attribute does.. And, using evaluate seems to be a better choice than just attribute since it covers more scenarios!
If someone can explain why attribute exists in the first place? More choices = more confusion.. :)
I was going through the process of creating a directive. Having gone through a few ups and downs I got through creating the directive ( widget ) and was finalizing the various attributes the directive will take.
I used the various options available like attribute, bind, evaluate, expression etc..
What I figured was that if you want to create a generic ponent, you can never tell how people will pass values to the the ponent.
Here is an illustration...
You are creating a new element ponent.. say
<hello name="__ARGUMENT__"></hello>
The name attribute for hello is the only variable in it. If you give it out to the public... these are the possible scenarios with which people may use this ponent.
case 1 :
<hello name="angular"></hello>
case 2 :
<hello name="{{name}}"></hello>
case 3 :
<div ng-repeat="name in names">
<hello name="name"></hello>
</div>
Now.. for different scenarios.. I have e to understand the various options provided. I cant think of a single scenario where you would ever want the 'attribute' since its a simple direct substitution of values from ponent to the template..
In your directive definition if you had defined the name as 'evaluate' instead of 'attribute'
if attribute :
<hello name="angular"></hello>
if evaluate :
<hello name="'angular'"></hello>
note the extra single quotes..
So as far as I can tell evaluate covers what attribute does.. And, using evaluate seems to be a better choice than just attribute since it covers more scenarios!
If someone can explain why attribute exists in the first place? More choices = more confusion.. :)
Share edited Oct 30, 2014 at 15:20 Rahil Wazir 10.1k11 gold badges44 silver badges65 bronze badges asked May 30, 2012 at 13:04 GanarajGanaraj 26.8k6 gold badges67 silver badges60 bronze badges 1- Ganaraj, it's great that you've brought this up. As I was reading through the directive doc this weekend, I came to similar conclusions. One other thing is the controller "require" attribute with the magic literal prefixes (?,^). The fact that ? makes the require dependency optional is a bit strange. Maybe have separate options, which of course plicates things more... – Dan Doyon Commented May 30, 2012 at 19:14
1 Answer
Reset to default 7We are well aware of this confusion, and will be cleaning it up in the future.
本文标签: javascriptNeed for value attribute in directive 39scope39Stack Overflow
版权声明:本文标题:javascript - Need for value attribute in directive 'scope' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261612a2442617.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论