您是否嘗試過在您的子指令定義對象上使用require
屬性?您將需要在孩子指示你的父母,並與require
屬性設置控制器定義來^container
,那麼你將有機會獲得母公司控制在link
功能作爲第四個參數:
angular.module('app', [])
.directive('container', function(){
return {
restrict : 'E',
transclude : true,
scope : {
},
template : 'container <ng-transclude> </ng-transclude>',
controller: function($scope){
// use this to add properties to the controller itself
// which you can then access in the child directive
this.container = "container";
},
link : function($scope){
}
};
})
.directive('child', function(){
return {
require: '^container',
restrict : 'E',
template : 'child container',
link : function($scope, element, attrs, containerController){
$scope.child = "child";
// logs: containerController Object {container: "container"}
console.log('containerController', containerController);
}
};
});
您需要手動跨屏。下面是我剛剛回答的一個問題:http://stackoverflow.com/a/32060662/968155 –