admin管理员组文章数量:1026989
Here's my directive:
app.directive("helloWorld", function() {
return {
restrict: "E",
scope: {
name: "bind"
},
template: "<div>a {{name}} a</div>"
};
});
Here's how I use it:
<hello-world name="John Smith"></hello-world>
I expect this page to be like this, when I run it:
<hello-world>
<div>a John Smith a</div>
</hello-world>
But for some reason, name
is not injected and actual result is like this:
<hello-world>
<div>a {{name}} a</div>
</hello-world>
Anything I'm missing? I'm using Angular JS 1.0.2
Here's my directive:
app.directive("helloWorld", function() {
return {
restrict: "E",
scope: {
name: "bind"
},
template: "<div>a {{name}} a</div>"
};
});
Here's how I use it:
<hello-world name="John Smith"></hello-world>
I expect this page to be like this, when I run it:
<hello-world>
<div>a John Smith a</div>
</hello-world>
But for some reason, name
is not injected and actual result is like this:
<hello-world>
<div>a {{name}} a</div>
</hello-world>
Anything I'm missing? I'm using Angular JS 1.0.2
Share Improve this question asked Oct 14, 2012 at 10:20 Andrey AgibalovAndrey Agibalov 7,6748 gold badges67 silver badges112 bronze badges1 Answer
Reset to default 14The scope declaration is strange. I'm not sure about the "bind"
declaration - maybe its something from the previous versions.
The current syntax for binding to a directive's attribute is like this:
return {
restrict: "E",
scope: {
name: "@name"
},
template: "<div>a {{name}} a</div>"
};
In general, @attributeName
. See here for more information on directives.
Here's my directive:
app.directive("helloWorld", function() {
return {
restrict: "E",
scope: {
name: "bind"
},
template: "<div>a {{name}} a</div>"
};
});
Here's how I use it:
<hello-world name="John Smith"></hello-world>
I expect this page to be like this, when I run it:
<hello-world>
<div>a John Smith a</div>
</hello-world>
But for some reason, name
is not injected and actual result is like this:
<hello-world>
<div>a {{name}} a</div>
</hello-world>
Anything I'm missing? I'm using Angular JS 1.0.2
Here's my directive:
app.directive("helloWorld", function() {
return {
restrict: "E",
scope: {
name: "bind"
},
template: "<div>a {{name}} a</div>"
};
});
Here's how I use it:
<hello-world name="John Smith"></hello-world>
I expect this page to be like this, when I run it:
<hello-world>
<div>a John Smith a</div>
</hello-world>
But for some reason, name
is not injected and actual result is like this:
<hello-world>
<div>a {{name}} a</div>
</hello-world>
Anything I'm missing? I'm using Angular JS 1.0.2
Share Improve this question asked Oct 14, 2012 at 10:20 Andrey AgibalovAndrey Agibalov 7,6748 gold badges67 silver badges112 bronze badges1 Answer
Reset to default 14The scope declaration is strange. I'm not sure about the "bind"
declaration - maybe its something from the previous versions.
The current syntax for binding to a directive's attribute is like this:
return {
restrict: "E",
scope: {
name: "@name"
},
template: "<div>a {{name}} a</div>"
};
In general, @attributeName
. See here for more information on directives.
本文标签: javascriptIn Angular JShow do I inject data from directive attribute to templateStack Overflow
版权声明:本文标题:javascript - In Angular JS, how do I inject data from directive attribute to template? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1743645409a2006127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论