Within my array named sports
, there is another array called leagues
, but I need to flatten these arrays using _.flatten
due to issues with Angular filters.
If you look at the data, inside the first array which contains a "name":"Live Betting"
, there is another array named "leagues"
that needs to be flattened.
[
{
"id": 26,
"name": "LIVE Betting",
"priority": 0,
"leagues": [
{
"id": 3042,
"parent": 1000,
"name": "LIVE BETTING - NBA",
"sport": {
"id": 26,
"name": "LIVE Betting"
},
...
Furthermore, the resolver with a promise is returning that array, which is retrieved by Sports
.
resolve: {
Sports: function(SportsFactory, AuthFactory, $q) {
var defer = $q.defer();
AuthFactory.getCustomer().then(function(customer) {
SportsFactory.getSportsWithLeagues(customer).then(function(sports) {
defer.resolve(sports);
});
});
return defer.promise;
}
}
Here is the controller where I invoke the resolver Sports
.
.controller('SportsController', function($scope, AuthFactory,
SportsFactory, Sports) {
console.log(angular.toJson(Sports, 'pretty'));
$scope.sports = [];
$scope.sportPromise = Sports;
For easier checking, you can access the Plunkr here: http://plnkr.co/edit/FJ45nV6gdwp3SkRglPeW?p=info