To view an example, please visit this link
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);
...
In Angular, symbol
, max
, and readonly
must be defined in the isolated scope object to access them from the parent scope.
This functionality is utilized here
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>
What is the purpose of using attrs
? Can all attributes passed through attrs
be accessed? Why can't you access the value of max
as attrs.max
instead of scope.max
?
Why reassign like this: attrs.max = scope.max
?
Since this application is developed by Angular authors, I expect a rationale behind these decisions.
Thank you.