[英]How to pass mutliple $scope values in ng-repeat angularjs?
This is my json data: 这是我的json数据:
{
"seendata": {
"count": 2,
"rows": [
{
"id": 8,
"contactCount": 2,
"group": {
"id": 7,
"groupname": "group1",
"createdAt": "2017-11-16T10:53:12.000Z",
"updatedAt": "2017-11-16T10:53:12.000Z"
}
}
]
},
"alldata": [
{
"id": 7,
"groupname": "group1",
"createdAt": "2017-11-16T10:53:12.000Z",
"updatedAt": "2017-11-16T10:53:12.000Z"
},
{
"id": 8,
"groupname": "group2",
"createdAt": "2017-11-16T10:54:41.000Z",
"updatedAt": "2017-11-16T10:54:41.000Z"
}
]
}
My api code: 我的api代码:
exports.getNewGroup = function (req, res) {
var globalObj={};
ContactGroup.findAndCountAll({
attributes: ['id', [sequelize.fn('COUNT', sequelize.col('group.id')),
'contactCount'
]],
include: [{
model: Group,
}],
}).then(seenData => { globalObj.seendata=seenData;return Group.findAll();})
.then(function (data) {
globalObj.alldata=data;
return res.status(200).send(globalObj);
}).catch(function (err) {
return res.status(400).send(err.message);
});
};
And my angular client side controller code: 和我的角度客户端控制器代码:
$http({
method: 'GET',
url: '/api/getnewgroup'
})
.then(function (response) {
$scope.groups = response.data.seendata.rows;
$scope.alldata = response.data.alldata;
console.log($scope.groups);
}, function (response) {
window.location.href = '/';
});
And my Jade file: 还有我的Jade文件:
tr(ng-repeat='group in groups')
td {{group.groupname}}
td {{group.contactCount}}
I want to display contactCount value as well as i want to display alldata.groupname values in my front end? 我想显示contactCount值,也想在前端显示alldata.groupname值?
Help me! 帮我!
I am getting {{group.contactCount}} correctly, but i am not getting {{group.groupname}} coming from alldata.groupname 我正确地获得了{{group.contactCount}},但是我没有得到{{group.groupname}}来自alldata.groupname
How to get? 如何获得? both values and how to pass multiple scopes and to be used in ng-repeat?
这两个值以及如何传递多个范围并在ng-repeat中使用?
Better take allData in to $scope.alldata = response.data.alldata; 最好将allData放入$ scope.alldata = response.data.alldata;
$http({
method: 'GET',
url: '/api/getnewgroup'
})
.then(function (response) {
$scope.groups = response.data.seendata.rows;
$scope.allData = response.data.alldata;
console.log($scope.groups);
}, function (response) {
window.location.href = '/';
});
And in your Jade file 并在您的Jade文件中
<tr ng-repeat='group in groups track by $index'>
<td>
<span ng-repeat='data in alldata'>data.groupname</span>
</td>
<td>group.contactCount</td>
</tr>
With help of rows $index you can fetch the data of allData also. 借助行$ index,您还可以获取allData的数据。 Hope it will work
希望它能工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.