私が持っている2つのディレクティブ最初のディレクティブがあり、レイヤビューと呼ばれる属性ディレクティブimapGridにコントローラによって満たされ、この値のキャプチャしたい属性を。
<ng-map mapid="mapid" layers-view="geo"></ng-map>
<imap-grid></imap-grid>
ng.map.directive.js
(function() {
'use strict';
angular
.module('app')
.directive('ngMap', ngMap);
function ngMap($q, $parse) {
return {
restrict: "E",
replace: true,
scope: {
layersView: '='
},
transclude: true,
controller: function($scope) {
this.getScope = function() {
return $scope;
};
},
link: function(scope, element, attrs, ctrl) {
}
};
}
})();
imap.grid.directive.js
(function() {
'use strict';
angular
.module('app')
.directive('imapGrid', imapGrid);
function imapGrid($q, $parse) {
return {
restrict: "E",
scope: true,
replace: false,
templateUrl: 'src/templates/imapGrid/grid.html',
require: '?^ngMap',
link: function(scope, element, attrs, ctrl) {
var scope = ctrl.getScope();
}
};
}
})();
ディレクティブimapGridのlayer-view属性の内容にアクセスしたい
私が今見ている問題は、あなたがrequire: '?^ngMap'
あなたのコードで参照しているということです。しかし、あなたのhtml<ng-map mapid="mapid" layers-view="geo"></ng-map> <imap-grid></imap-grid>
は、それng-map
がimap-grid
したがってrequire: '?ngMap'
、ngMapはimapGridの兄弟ディレクティブであるため、を使用して取得します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加