best way to get a specific object from and array without looping

前端 未结 2 1264
日久生厌
日久生厌 2021-01-20 20:03

In one of the controllers of my angular application i have a variable set as follows.

SomeService.get({}, function(data){
    // this sets xyz as the list of         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 20:31

    Though this is already answered a year ago, since this is one of the top results in Google, I thought I can add the following suggestion which may be the easiest way to filter. After injecting $filter into your controller,

    var result = $filter('filter')($scope.xyz, {id:"1"});
    

    reference: https://docs.angularjs.org/api/ng/filter/filter

提交回复
热议问题