Reputation: 83
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.
Upvotes: 4
Views: 4233
Reputation: 33554
If 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.
more info on scope and '@'
in the Angular Directives page
Upvotes: 6