저는 Angular와 한동안 작업했습니다. 그러나 오늘 내 사용자 지정 지시문의 속성이 올바르게 바인딩되지 않은 것이 매우 이상하다는 것을 알았습니다. 다음은 코드 발췌입니다.
<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;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다