这是我的问题,我想显示每个用户的票数,但它只显示最后一个值。我希望在每个用户名之间显示他得到的门票数量。
Controller.js:
angular.controller('homeCtrl', ['$scope', 'dropdown', 'userdisplay', 'displayfilter',
function($scope, dropdown, userdisplay, displayfilter) {
$scope.test = "coucou";
$scope.displaycompany = function() {
var token = "xxxxxxx";
dropdown.send(token).then(function(data) {
$scope.usertab = data.organizations;
console.log($scope.usertab);
});
}
$scope.displayuser = function(id) {
var token = "xxxxxxxxx";
userdisplay
.send(token, id)
.then(function(data) {
console.log(data);
$scope.userbyorga = data.users;
console.log(data.users);
for (i = 0; i < data.users.length; i++) {
var userid = data.users;
var userarray = JSON.stringify(userid);
localStorage.setItem("myid", userarray);
}
})
.then(function() {
var tabuser = JSON.parse(localStorage.getItem("myid"));
console.log(tabuser);
for (i = 0; i < tabuser.length; i++) {
console.log(tabuser[i].id);
displayfilter
.user(token, tabuser[i].id)
.then(function(data) {
console.log(data.tickets.length);
$scope.numtickets = data.tickets;
})
}
})
};
}
])
以下是我的观点:
<div class="btn-group" uib-dropdown dropdown-append-to-body>
<button ng-click="displaycompany()" id="btn-append-to-body" type="button" class="btn btn-primary" uib-dropdown-toggle>
Entreprises <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="btn-append-to-body">
<li ng-repeat="item in usertab track by $index" ng-click="displayuser(item.id)">{{item.name}}</a>
</li>
</ul>
</div>
<ul ng-repeat="user in userbyorga track by $index">{{user.name}}
<li>{{numtickets.length}}</li>
</ul>