1

I am having a problem where my controllers are running before initialization of my app, and I came across this solution. The problem is I have several abstract routes and setting those abstract routes as children just breaks everything.
Here is some of the relevent code:

app.config(function($stateProvider, $urlRouterProvider, $locationProvider, stateHelperProvider){
  $urlRouterProvider.otherwise('/venues/feed');
  // $locationProvider.html5Mode(true);
  stateHelperProvider.setNestedState({
    name: 'root',
    // url: '/root',
    template: '<ui-view/>',
    abstract: true,
    resolve: {
      bootstrapper: function($http, $rootScope, $cookies) {
        console.log('once upon a time')
        return  $http.get('/__/env.json')
        .then(function(response) {
          $rootScope.apiUrl = response.data.apiUrl;
          $rootScope.googleMapsApiKey = response.data.googleMapsApiKey;
          $rootScope.currentLocationLat = 40.7589;
          $rootScope.currentLocationLng = 73.9851;
        })
        .then(function(){
          hotelId = ''
          if ($cookies.get('hotel') === undefined){
            $http.get($rootScope.apiUrl + '/hotels')
            .then(function(dbHotels){
              hotelId = dbHotels.data[0]._id
              $cookies.put('hotelId', hotelId)
            })
          }

          if ($cookies.get('userId') === undefined){
            $http.get($rootScope.apiUrl + '/users')
            .then(function(dbUsers){
              index = dbUsers.data.length - 1
              userId = dbUsers.data[index]._id
              $cookies.put('userId', userId)
              $rootScope.$broadcast('update-itinerary-icon')
            })
          }
        })
      }
    },
    children: [{
      name:'venues',
      url: '/venues',
      abstract: true,
      template:'<ui-view>'
    }, 
    {    
      name:'venues.feed',
      url: '/feed?favorites&priceLevelMin&priceLevelMax',
      reloadOnSearch: false,
      templateUrl:'./views/venue/feed.html',
      controller: 'VenueController'
    }, {    
      name:'venues.details',
      url: '/:venue_id',
      templateUrl:'./views/venue/details.html',
      controller:'VenueController'
    }, {    
    ...more routes...
    }]
  });
  $locationProvider.html5Mode(true);
});

How to I get this solution to work with my routes?

Community
  • 1
  • 1
jmona789
  • 2,711
  • 6
  • 24
  • 57

0 Answers0