请看这里的例子
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);
...
Run Code Online (Sandbox Code Playgroud)
角需要symbol,max,readonly以在所述分离的范围对象从父范围访问它来限定.
它在这里使用
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>
那么,目的是attrs什么?无法访问所有传递的属性attrs.为什么不能访问max的值attrs.max而不是scope.max
为什么要分配回来attrs.max = scope.max?
由于这个应用程序是由Angular作者编写的,我希望有一个理由.
谢谢.
我正在尝试将模板文件views/infowindow.html作为我的InfoWindow内容包含在我编写的服务中以启动google maps api:
for ( var count = locations.length, i = 0; i < count; i++ ) {
var latLng = locations[i],
marker = new google.maps.Marker({
…
}),
infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(
marker,
'click',
(function( marker , latLng ){
return function(){
var content = '<div ng-include src="\'infowindow.html\'"></div>';
infowindow.setContent( content );
infowindow.open( Map , marker );
}//return fn()
})( marker , latLng )
);//addListener
}//for
Run Code Online (Sandbox Code Playgroud)
但是,content当Angular 插入InfoWindow时似乎没有处理(当通过Dev Tools检查代码时,插入的代码是<div ng-include src="'views/infowindow.html'"></div>).
我希望Angular在将它插入InfoWindow之前预先处理我的包,但是没有.
我正在尝试做什么?
我想我将不得不以某种方式缓存模板,然后传递给它infowindow.setContent() …