1
我想ChildCtrl
只有在點擊上面的按鈕時才能初始化。這怎麼可能?AngularJS:如何從另一個控制器內動態初始化模板中的控制器
<div ng-controller="ParentCtrl">
<button>CLICK TO INIT CHILD CTRL</button>
<div class="child-container">
<div ng-controller="ChildCtrl" ng-include="'templates/child.html'" />
</div>
</div>
謝謝!沒有想到 –
@YossiShasho請記住'ng-if'創建一個獨立的範圍。如果'ParentCtrl'將'thing'添加到它的作用域中,那麼由於'ng-if',現在在'ChildCtrl.scope'內部以'$ parent.thing'的形式被訪問。 – cgTag
我知道,那是我做的。謝謝! –