App.factory data, like WHERE in php


#1

Hi everyone,

I would like to know, if it is possible to select specifics data from services.js file.

here is the factory :

`app.factory(‘People’, function() {
var artists = [
{
“id”: 1,
“surname”: “Tony”,
“location”: {
“country”: “United States”,
“administrative_area_level_1”: “California”,
“administrative_area_level_2”: “Los Angeles County”,
“locality”: “Los Angeles”,
“neighborhood”: “Compton”
}
}, {
“id”: 2,
“surname”: “Stark”,
“location”: {
“country”: “France”,
“administrative_area_level_1”: “Île-de-France”,
“administrative_area_level_2”: "Paris,
“locality”: “75019”
}
}];

return {
    all: function() {
        return artists;
    },
    get: function(artistId) {
      for (var i = 0; i < artists.length; i++) {
        if (artists[i].id === parseInt(artistId)) {
            return artists[i];
        }
      }
      return null;
    }
};

});`

The way I want to filter those data, is by swiping (right and left), divs, and the current div will decide at what level I am (“country”,“administrative_area_level_1”,“administrative_area_level_2”,“locality”,“neighborhood”)

To sum up, if the actual div (ng-init) is country, and my country is United States, it will only show users where country is United States (here Tony will only be shown).

Thanks for the help !