I am unable to get resolved data (via resolve object) from ui router pre-loaded into a component controller. the properties are showing up in the component's this object, but all properties are undefined. Why is this happening? I have been stuck on this for a while now...
here is the component:
.component('wLoans', {
template: require('./loans.html'),
controller: LoansController,
bindings: {
settings: '<',
labels: '<'
}
});
this.settings and this.labels appear, but they are undefined. when I console.log inside resolve.settings below, I can see the promise itself. in the promise below, value contains the return data I want:
below is the state I am working on with UI router:
{
name: 'loans',
parent: 'app',
url: '/loans',
data: {
authRequired: true
},
views: {
content: {
template: '<w-loans></w-loans>'
}
},
resolve: {
labels(LabelService) {
'ngInject';
return LabelService.fetch();
},
settings(SettingsService) {
'ngInject';
console.log(SettingsService.fetch());
return SettingsService.fetch()
},
module($q, $ocLazyLoad, LabelService) {
'ngInject';
return $q((resolve) => {
require.ensure([], (require) => {
let mod = require('pages/loans');
$ocLazyLoad.load({ name: mod.name });
resolve(mod.name, LabelService.fetch());
}, 'loans');
});
}
}
}
here is the fetch function from the service that's being called in the route:
function fetch() {
// return $http.get(require('!!file!mocks/settings.json'), {
return $http.get(`${DEV_API_URL}/settings`, {
cache: settingsCache,
transformResponse: [
...$http.defaults.transformResponse,
transformResponse
]
})
.then(({ data }) => {
angular.extend(model, data);
settingsCache.put('store', model);
return model;
});
}
Any help is appreciated!
UPDATE: using ui router 1.0.0-beta.1