sim*_*mmu 4 javascript angularjs angularjs-directive
在页面上
<rn-text-edit rn-scope="profile.first_name"></rn-text-edit>
Run Code Online (Sandbox Code Playgroud)
在js
app.directive("rnTextEdit", function () {
return {
restrict: 'E',
replace: true,
template:'<span>{{'+rn-scope+'}}</span>'
}
});
Run Code Online (Sandbox Code Playgroud)
我知道我可以替换DOM并通过链接访问属性.我想知道是否有一种方法可以将指令的属性传递给模板.
如果您只是显示值:
<rn-text-edit rn-scope="{{profile.first_name}}"></rn-text-edit>
Run Code Online (Sandbox Code Playgroud)
-
app.directive("rnTextEdit", function () {
return {
restrict: 'E',
replace: true,
scope: {
rnScope: '@'
},
template: '<span>{{rnScope}}</span>'
}
});
Run Code Online (Sandbox Code Playgroud)
如果指令需要修改该值,您可以使用'='并跳过双重curlies.
在范围和更多信息'@'的角度指令页面
| 归档时间: |
|
| 查看次数: |
4209 次 |
| 最近记录: |