Saturday 6 July 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?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...