1
后,我得到了我的决心账户和人阵,我该如何访问人和账户组件控制器?我也尝试过在主ctl中定义acctTally,并将其绑定到组件,但没有运气。组件,在Angularjs1.5结合 - 从一个控制器将数据传递到另一个
在那里我遇到的问题,我可以将人们和户口只需找到的组件,并将其接入分量模板,但我想这样做在组件控制器或者阵列上的工作。我缺少什么关键概念?
主控制器
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>
非常感谢,我曾尝试使用$ onInit,但忘记将它附加到CTRL! – user5852854