I am trying to build the first angular component using ngRoute, and so far I canβt get the data for the solution. configurations:
.when('/myfirstcomponent', { template: '<myfirstcomponent claimKeys="$resolve.claimKeys"></myfirstcomponent>', resolve: { claimKeys: ['$http', function($http) { $http.get('server/claimkeys.json').then((response) => { var claimKeys = response.data.DATASET.TABLE; return claimKeys; }); }] } })
component:
.component('myfirstcomponent', { bindings: { 'claimKeys': '@' }, templateUrl: 'components/component.html', controller: [function() { this.$onInit = function() { var vm = this; console.log(vm.claimKeys); }; }]
In html for a component, there is simply a p element with some random text, which is all.
I can see when I am debugging that I am receiving data, but I cannot access it on the component controller ...
EDIT: Thanks to the answer below, I fixed my problem. This had nothing to do with the problem with asynchronous calls, but with how I defined my route and component. See the code below for a fix. Thanks again.
source share