如何将抽象路由设置为抽象路由的子节点?

时间:2016-11-18 18:26:29

标签: angularjs angular-ui-router

在我的应用初始化之前我的控制器正在运行时出现问题,我遇到了这个solution。问题是我有几个抽象的路线,并设置那些抽象的路线,因为孩子只是打破了一切 以下是一些相关的代码:

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);
});

如何让这个解决方案与我的路线一起使用?

0 个答案:

没有答案