我有两个指令,第一个指令有一个名为“layer-view”的属性,该属性由指令中的 Controller 填充 imapGrid 希望捕获此值属性。
html
<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 的同级指令
关于javascript - 从另一个指令获取指令的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35976073/