1

Work on Asp.net mvc.As i am new in angular js.Stuck on basic issue,want to know how to filter api result in angular.services1 and services2 get respectively serviceId=1 and serviceId=2 datas.My filter criteria is ServiceId

Here is my angular syntax

MyPageService.GetOthersByID('/api/XXXXXX/GetServiceUsableBalance').success(function (data) {


    $scope.services1 = arr1;
    $scope.services2 = arr2;
    }

Bellow is my Api response.

LiveCustomerMT4ServiceID CustomerID    ServiceID   ServiceInstanceID    UserNa
------------------------ -------------------- ----------- -------------------- ---
7                        40                   2           2015052672           
8                        40                   1           2015052672           
9                        40                   2           2015052672           
9                        40                   1           2015052672  

Angular invoke api successfully and also get response but failed to filter success response.

1
  • What's your filter criteria? Not getting exactly what do you want? Commented Feb 17, 2017 at 9:07

2 Answers 2

0

Using javascript filter() function:

$scope.services1 = data.filter(element => element.serviceId == 1);
$scope.services2 = data.filter(element => element.serviceId == 2);
Sign up to request clarification or add additional context in comments.

1 Comment

filter is not a function I get.
0

Following is the demo to get result as per your request:-

MyPageService.GetOthersByID('/api/XXXXXX/GetServiceUsableBalance').success(function (data) {
   $scope.services1 = $filter('filter')(data, { serviceID: 1 }, true);
   $scope.services2 = $filter('filter')(data, { serviceID: 2 }, true);
});

Note:- Please don't forget to inject $filter to your controller

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.