我有以下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