【发布时间】:2012-12-27 09:10:36
【问题描述】:
请看例子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 需要在隔离作用域对象中定义 symbol 、 max 、 readonly 以从父作用域访问它。
使用here
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>
那么,attrs 的目的是什么?无法访问通过attrs 传递的所有属性。为什么不能将 max 的一个值访问为 attrs.max 而不是 scope.max
为什么要像 attrs.max = scope.max 这样分配回来?
由于这个应用程序是由 Angular 作者编写的,我期待一个原因。
谢谢。
【问题讨论】:
标签: javascript angularjs