请参阅例如hereAngularjs指令:隔离范围和ATTRS
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);
...
角需要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作者编写的,我期待一个理由。
谢谢。
请查看此处http:///stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope/14063373#14063373 –