AngularJS Transclude директива улов от другой директивы
Я получил директиву transcluded, например, директиву aDirective и другую случайную директиву bDirective. Моя задача: я хочу получить переменную области видимости aDirective и перехватить ее в bDirective.
angular.module('myApp',[])
.controller('bDirective',['$scope',function(scope){
scope.getScopeVar = function () {
// here I want to get aDirective - s 'someVar' variable
scope.someVar;
debugger;
};
scope.getScopeVar();
}])
.directive('aDirective',function(){
return{
scope:{},
transclude:true,
template:'<div>123</div>',
link: function(scope, element, attrs, controller, transclude){
scope.someVar = 'asd';
transclude(scope, function (clone) {
element.append(clone);
});
}
};
});
Какие-либо решения? С уважением, Ник.
1 ответ
Вложенная директива должна require
директива сверху. Тогда он может получить свой контроллер в виде link
аргумент функции (четвертый).
.directive('nestedDirective', function(){
return {
require: '^aDirective',
link: function (scope, elements, attrs, aDirectiveController) {
// access aDirectiveController's methods or properties
}
}
})