on the Page
<rn-text-edit rn-scope="profile.first_name"></rn-text-edit>
on the js
app.directive("rnTextEdit", function () {
return {
restrict: 'E',
replace: true,
template:'<span>{{'+rn-scope+'}}</span>'
}
});
I know I can replace the DOM and access the attribute through link. I wonder if there is a way of passing the directive's attribute to a template.
on the Page
<rn-text-edit rn-scope="profile.first_name"></rn-text-edit>
on the js
app.directive("rnTextEdit", function () {
return {
restrict: 'E',
replace: true,
template:'<span>{{'+rn-scope+'}}</span>'
}
});
I know I can replace the DOM and access the attribute through link. I wonder if there is a way of passing the directive's attribute to a template.
Share Improve this question asked May 1, 2013 at 20:47 simmusimmu 731 silver badge5 bronze badges 1- Can the directive use an isolate scope? – Mark Rajcok Commented May 1, 2013 at 21:24
1 Answer
Reset to default 6If you are just displaying the value:
<rn-text-edit rn-scope="{{profile.first_name}}"></rn-text-edit>
-
app.directive("rnTextEdit", function () {
return {
restrict: 'E',
replace: true,
scope: {
rnScope: '@'
},
template: '<span>{{rnScope}}</span>'
}
});
If the directive needs to modify the value, you could use '='
and skip the double curlies.
fiddle
more info on scope and '@'
in the Angular Directives page
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745320923a4622438.html
评论列表(0条)