首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ng-repeat angularjs中使用多个响应?

如何在ng-repeat angularjs中使用多个响应?
EN

Stack Overflow用户
提问于 2017-12-07 18:15:42
回答 0查看 371关注 0票数 2
代码语言:javascript
复制
$http({
                method: 'GET',
                url: '/api/getnewgroup'
            })
            .then(function (response) {
                $scope.groups = response.data;
            }, function (response) {
                window.location.href = '/';
            });

        $http({
            method: 'GET',
            url: '/api/getnewgroupforprofsms'
        })
        .then(function (response) {
            $scope.profsmsgroups.groups = response.data;
        }, function (response) {
            window.location.href = '/';
        });

我在$scope.groups和$scope.profsmsgroups.groups两个多范围内得到了两个不同的响应。

代码语言:javascript
复制
tr(ng-repeat='group in profsmsgroups.groups')
   td
   input(type = 'checkbox', ng-model='group.select')
   td {{group.groupname}}
   td {{group.contactsCount}}

我的组名在$scope.profsmsgroups.groups作用域中,所以td {{group.groupname}}显示正确

但是我在$scope.groups有contactsCount

那么如何使用多ng-repeat响应呢?

我的$scope.profsms.groups json:

代码语言:javascript
复制
[
    {
        "id": 7,
        "groupname": "Angular",
        "createdAt": "2017-12-07T10:49:31.000Z",
        "updatedAt": "2017-12-07T10:49:31.000Z",
        "contactgroups": [
            {
                "id": 7,
                "contact": {
                    "gsm": "4779306474"
                }
            }
        ]
    },
    {
        "id": 3,
        "groupname": "Vue",
        "createdAt": "2017-12-05T09:36:15.000Z",
        "updatedAt": "2017-12-05T09:36:15.000Z",
        "contactgroups": []
    },
    {
        "id": 5,
        "groupname": "React",
        "createdAt": "2017-12-05T09:36:29.000Z",
        "updatedAt": "2017-12-07T10:46:28.000Z",
        "contactgroups": []
    },
    {
        "id": 6,
        "groupname": "Node",
        "createdAt": "2017-12-06T09:47:24.000Z",
        "updatedAt": "2017-12-07T10:46:35.000Z",
        "contactgroups": []
    }
]

我的$scope.groups响应

代码语言:javascript
复制
[
    {
        "id": 3,
        "groupname": "Vue",
        "contactsCount": 0,
        "contactgroups": []
    },
    {
        "id": 5,
        "groupname": "React",
        "contactsCount": 0,
        "contactgroups": []
    },
    {
        "id": 6,
        "groupname": "Node",
        "contactsCount": 0,
        "contactgroups": []
    },
    {
        "id": 7,
        "groupname": "Angular",
        "contactsCount": 1,
        "contactgroups": [
            {
                "id": 7
            }
        ]
    }
]
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47692641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档