请在此处查看示例
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 需要在隔离范围对象中定义symbol
,以从父范围访问它。max
readonly
它在这里使用
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>
那么,这样做的目的是attrs
什么?无法访问通过的所有属性attrs
。为什么不能一个访问 max asattrs.max
而不是scope.max
为什么要分配回来 like attrs.max = scope.max
?
由于这个应用程序是由 Angular 作者编写的,我希望有一个理由。
谢谢。