簡體   English   中英

如何在ng-repeat angularjs中傳遞多個$ scope值?

[英]How to pass mutliple $scope values in ng-repeat angularjs?

這是我的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"
        }
    ]
}

我的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);
    });
};

和我的角度客戶端控制器代碼:

$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 = '/';
      });

還有我的Jade文件:

tr(ng-repeat='group in groups')
 td {{group.groupname}}
 td {{group.contactCount}}

我想顯示contactCount值,也想在前端顯示alldata.groupname值?

幫我!

我正確地獲得了{{group.contactCount}},但是我沒有得到{{group.groupname}}來自alldata.groupname

如何獲得? 這兩個值以及如何傳遞多個范圍並在ng-repeat中使用?

最好將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 = '/';
    });

並在您的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>

借助行$ index,您還可以獲取allData的數據。 希望它能工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM