Please see the example here
foodMeApp.directive('fmRating', function() {
return {
restrict: 'E',
scope: {
symbol: '@',
max: '@',
readonly: '@'
},
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
attrs.max = scope.max = parseInt(scope.max || 5, 10);
...
Angular needs symbol
, max
, readonly
to be defined in the isolated scope object to access it from parent scope.
it is used here
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>
So, what is the purpose of attrs
? Can't one access all the attributes passed through attrs
. Why can't one access value of max as attrs.max
instead of scope.max
Why assign back like attrs.max = scope.max
?
Since this app is written by Angular authors, I expect a reason.
thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…