这是我的指示:
- app.directive("helloWorld",function() {
- return {
- restrict: "E",scope: {
- name: "bind"
- },template: "<div>a {{name}} a</div>"
- };
- });
这是我如何使用它:
- <hello-world name="John Smith"></hello-world>
当我运行它时,我希望这个页面是这样的:
- <hello-world>
- <div>a John Smith a</div>
- </hello-world>
但由于某种原因,名称不会被注入,实际结果如下:
- <hello-world>
- <div>a {{name}} a</div>
- </hello-world>
我缺少什么?我正在使用Angular JS 1.0.2
解决方法
范围声明很奇怪.我不确定“绑定”声明 – 可能是以前版本的东西.
绑定到指令属性的当前语法如下所示:
- return {
- restrict: "E",scope: {
- name: "@name"
- },template: "<div>a {{name}} a</div>"
- };
通常,@ attributeName.在这里查看more information on directives.