我被告知將AngularJS的component
合併到我的應用程序中。在使用組件之前,我有兩個控制器,分別是patentList
和patentItem
。當用戶點擊patent list
中的項目時,它將載入關於該具體patent item
的更多詳細信息。如何訪問組件中的父母控制器數據在angularjs
現在我已將控制器包含在components
中,數據無法填充patent item
表。這是(我認爲)patent item
是patent list
的孩子,我能夠訪問父母的數據。
我的問題是,我該如何訪問父controller
現在我已經使用components
的數據?任何幫助將不勝感激
列表專利
<tr ng-repeat="x in $ctrl.patents">
<td ng-click="$ctrl.select(x)"><a ui-sref="patents.list.item({id: x.id})">{{x.applicationNumber}}</a></td>
<td ng-bind="x.clientRef"></td>
<td ng-bind="x.currentRenewalCost">$</td>
<td ng-bind="x.costBandEndDate"></td>
<td ng-bind="x.renewalCostNextStage"></td>
<td ng-bind="x.renewalDueDate"></td>
</tr>
專利項目
<tr ng-repeat="x in $ctrl.patentItem">
<td><input type="text" ng-model="x.patentApplicationNumber"></td>
<td><input type="text" ng-model="x.clientRef"></td>
<td><input type="text" ng-model="x.renewalStatus"></td>
<td><input type="text" ng-model="x.costBandEndDate"></td>
<td><input type="text" ng-model="x.renewalCostNextStage"></td>
<td><input type="text" ng-model="x.renewalDueDate"></td>
</tr>
app.js
var app = angular.module('myApp', ['ngRoute', 'ui.router']);
app.config(function($stateProvider, $locationProvider, $urlRouterProvider, localStorageServiceProvider) {
app.component('patentList', {
scope: {},
templateUrl: "templates/patents/list/list-patents.htm",
controller: function(loadPatentsService, loadPatentItemService) {
var vm = this;
vm.select = function(item) {
vm.patentItem = loadPatentItemService.select(item);
console.log(item)
}
}
})
});
app.component('patent', {
scope: {},
templateUrl: "templates/patents/list/patent-item.htm",
controller: function(patentTabService, loadPatentItemService) {
var vm = this;
//LOAD OF CODE FOR A TAB PANEL
}
})
app.factory('loadPatentItemService', function() {
var factory = {};
factory.select = function(item) {
factory.storeSelect = [];
selectedItem = item;
factory.storeSelect.push(selectedItem)
return [selectedItem];
}
return factory;
})
app.factory('patentTabService', function() {
var factory = {};
//CODE RELATED TO THE TAB PANEL
return factory;
});
爲什麼是一個配置塊內的'patentList'成分的定義是什麼?還請顯示路由器的狀態表。 – georgeawg