从我的解析中获取帐户和人员数组后,我如何访问组件控制器中的人员和帐户?我还尝试了在主 ctl 中定义 acctTally 并将其绑定到组件,但没有成功。
我可以将人员和帐户绑定到组件并在组件模板中访问它,但是我想在组件控制器中的任一数组上进行工作是我遇到问题的地方。我错过了什么关键概念????
主控制器
angular.module('hellosolarsystem')
.controller('AcctCtrl', function($scope, accounts, people){
$scope.accounts = accounts;
$scope.people = people;
});
主模板
<nav-bar></nav-bar>
<acct-list people="people" accounts="accounts"></acct-list>
零件
function aCtrl(){
var ctrl = this;
ctrl.acctTally = [];
ctrl.uniqueAcct = [];
//Array of all accounts
$scope.people.data.forEach(function(person){
person.account_types.forEach(function(account){
ctrl.acctTally.push(account.name);
})
});
}
angular.module('hellosolarsystem').component('acctList', {
bindings: { accounts: '<',
people: '<'
},
controller: aCtrl,
templateUrl: 'javascripts/app/components/accounts/acctsList/index.html'
})
组件模板
<table class = "table">
<thead>
<tr>
<th>Accounts</th>
<th>Number of Accounts Assigned Users</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "acct in $ctrl.acctTally">
<td>{{acct.name}}</td>
<td>{acct.tally}}<</td>
<td>
<button class = "btn btn-info" ng-click = "editUser($index)">Edit</button>
<button class = "btn btn-danger" ng-click = "deleteUser($index)">Delete</button>
</td>
</tr>
</tbody>
</table>