我有两个指令,第一个指令有一个名为layer-view 的属性,它由指令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
的图层视图属性的内容答案 0 :(得分:0)
我现在看到的问题是您在代码中引用了require: '?^ngMap'
..但是您的HTML
<ng-map mapid="mapid" layers-view="geo"></ng-map>
<imap-grid></imap-grid>
清楚地告诉ng-map
不是imap-grid
所以使用require: '?ngMap'
来获取ngMap,因为它是imapGrid的兄弟指令