Saturday, July 6, 2019
angularjs - How to set abstract routes as children of an abstract route?
Answer
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: '',
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:''
},
{
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?
Subscribe to:
Post Comments (Atom)
plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV
In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...
-
This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programm...
-
I need to do the following: My current address looks like: https://www.domain.com I want to redirect with htaccess: www.domain.com TO https:...
-
using namespace std; So far in my computer science courses, this is all we have been told to do. Not only that, but it's all tha...
No comments:
Post a Comment