範圍內假設下面的藍圖代碼:訪問主控制器從指令
<div ng-controller="myCtrl">
<div ng-repeat="...">
<div ng-repeat="...">
<div ng-repeat="...">
<div ng=if="..." my-directive>
</div>
</div>
</div>
</div>
</div>
myApp.directive('myDirective', function() {
return {
controller: function($scope){
console.log('controller scope');
console.log($scope);
},
link:function(scope,element){
console.log('link scope');
console.log(scope);
}
}
});
在控制檯輸出都會指向由ng-if
指令創建範圍。我的問題是如何從指令中訪問myCtrl的範圍。當然不是使用$ parent。$ parent ....
在回答之前,請先閱讀問題! –
如果你閱讀我的答案,它會幫助你。如果你繼承了範圍,你可以訪問父範圍,在這種情況下,它是你的控制器的範圍。 –
@ILIAS,你在找什麼?從指令訪問控制器的範圍.... –