I am pulling back some route dependent data and the JSON is returned just fine from the server, but I am unsure how to actually access the object once I am in my controller. I have tried a few different things, such as putting the .then() inside the resolve, but that did not work.
resolve: {
menus: function ($http) {
var httpSource = this.httpSource = location.protocol + '//' + location.hostname;
const url = `${this.httpSource}/api/package/menus`;
return $http.get(url);
}
}
I did also try this
resolve: {
menus: function ($http) {
var httpSource = this.httpSource = location.protocol + '//' + location.hostname;
const url = `${this.httpSource}/api/package/menus`;
var menuData;
$http.get(url).then(response => {
menuData = response.data.Data;
})
return menuData;
}
}
I just simply cannot figure out how to load it into a controller property.
I tried to follow this, but the variable is not injected in the constructor -- https://medium.com/opinionated-angularjs/advanced-routing-and-resolves-a2fcbf874a1c#.2xzq32cwo
I attempt to load it with
this.menuData = $state.current.resolve.menus;
And I end up with this object.
"$http", function $stateProvider.state.state.resolve.menus($http)]
I am sure there is something fundamental I am missing here, but being new to Angular, I do not see it. Basically, my object is the full function definition and not the return data.Data.
My controller constructor.
static $inject = ['PackageService', '$stateParams', '$state', 'menus'];
constructor(packageService: Service.IPackageService, $stateParams, $state, DTOptionsBuilder, DTColumnDefBuilder, public logger: ILogger, public menus: any) {