У меня есть следующий HTML структура:Угловой 1,4 - получить родительский контроллер свойство
<div class="order-table-page" ng-controller="SummaryController as summaryCtrl">
<h3>Summary</h3>
<!-- Statutes summary information -->
...
<!--List of orders with selected statuses-->
<div ng-controller="OrderTableController as orderTableCtrl">
...
</div>
</div>
Так, OrderTableController является дочерним SummaryController. Теперь в дочернем контроллере я хочу получить доступ к родительскому свойству. В родительском классе я определяю:
orderApp.controller('SummaryController', ['$location', 'ordersApi', function($location, ordersApi){
var ctrl = this;
ctrl.summary = [];
ctrl.test = 'test';
...
}]);
И контроллер ребенка я пытаюсь получить свойство «тест»:
orderApp.controller('OrderTableController', ['$location', '$scope', 'ordersApi', function($location, $scope, ordersApi){
var table = this;
table.orders = [];
console.log("Table orders 1");
console.log($scope.$parent.test);
...
}]);
Я ожидаю, что $ сферы $ Родитель будет содержать SummaryController сферы.. Но я не уверен, что он содержит, потому что $scope.$parent.test
не определен и $ scope. $ Parent имеет свойство с именем summaryCtrl.
Мой вопрос: как получить родительскую собственность «тестовая» форма OrderTableController?
Вы пробовали $ объем $ parent.summaryCtrl.test? –
@SergioFandino да, я пробовал, и он работает. Но я не понимаю, почему $ scope. $ Parent.test этого не делает. Похоже, что с моим кодом что-то не так. – Tamara