我创建了一个带有指令的可重用组件,如下所示:
count
menu.html:
app.directive("menu", function () {
return {
restrict: 'AE',
templateUrl: '/menu.html',
scope: {
title: '=title'
}
};
});
显然我想从外面传递<div>{{title}}</div>
属性,并且显示在title
内。
在main.html中的用法:
menu.html
结果:标签未解决。为什么呢?
答案 0 :(得分:3)
你必须这样声明:
app.directive("menu", function () {
return {
restrict: 'AE',
templateUrl: '/menu.html',
scope: {
title: '@'
}
};
});
Text Binding (Prefix: @)
One-way Binding (Prefix: &) (for functions)
Two-way Binding (Prefix: =)
This SO post更深入地了解@ vs =
答案 1 :(得分:0)
有三种类型的指令绑定:
所以在你的情况下,如果你只关心显示文本,你会使用&#39; @&#39;符号