角度指令作用域绑定在 ng-repeat中不起作用
Angular Directive scope binding not working in ng-repeat
我已经使用 Angular 一段时间了。但是,今天我发现我的自定义指令中的 attrs 没有正确绑定很奇怪。以下是代码摘录:
<div ng-repeat="item in items">
<io-map geo-location-x="item.data.x" geo-location-y="item.data.y" zoom-level="item.data.zoom"></io-map>
</div>
angular.directive('io-map', function() {
return {
restrict: 'EA',
scope: {
geoLocationX:'=',
geoLocationY:'=',
zoomLevel:'='
},
template: '<div id="map-' + Math.round(Math.random()*100000000) + '" style="height:400px"></div>',
link: function (scope, element, attrs) {
//Some logic...
//I checked the attrs here, and found attrs.geoLocationX and so on are just plain strings like "item.data.x", meaning they are not bound, while I can assure you that item.data.x has its value.
}
}
})
怎么了?提前谢谢。
将独立作用域与=
绑定一起使用不会使用 attrs
解析属性值。
scope: {
geoLocationX:'=',
geoLocationY:'=',
zoomLevel:'='
},
您应该改用scope
:
link: function (scope, element, attrs) {
//Some logic...
//use
var valueForGeoLocationX = scope.geoLocationX;
}
相关文章:
- 角度无线电按钮ng模型不起作用
- 角度Js ng-disabled不起作用
- 为什么ng节目不起作用
- 带有粘性标题的角度ng视图不起作用
- select中布尔值的Angularjs ng值不起作用
- AngularJS触发ng更改不起作用
- Angular js-ng选项不起作用
- 实时 Angular js ng-hide 不起作用
- 当输入字段位于 ng 重复中时,ng 禁用不起作用
- AngularJS ng重复不起作用
- AngularJS:ng-repeat不起作用
- 尝试输出多维数组时,AngularJS中的ng repeat不起作用
- 在Angularjs应用程序中,使用嵌套对象属性过滤ng repeat不起作用
- AngularJS中不同的过滤器方法"ng-repeat"不起作用
- Angular JS - Binding view和app.js - ng-repeat不起作用
- 将ng-model绑定到ng-repeat不起作用
- ng init与ng repeat不起作用
- Ng-repeat不起作用AngularJs
- Angular js ng-repeat不起作用
- 为什么ng-repeat不起作用