I am trying to use resolve in order to ensure that data has been loaded prior to a view state displaying on screen. This resolve is dependent on a selection which the user will have made in a previous state.
As such, I need to perform a get request with a parameter.
The problem is that I have no idea how to set the parameter from within the app. I have tried
.get('https://.../questions', {params: {gender: $scope.user.gender}})
.get('https://.../questions', {params: {gender: user.gender}})
.get('https://.../questions', {params: {gender: vm.user.gender}})
The only thing which works is:
.get('https://.../questions', {params: {gender: 'Male'}})
Bigger code snippet below to give some context.
.state('questionnaire', {
url: '/questionnaire',
templateUrl: 'templates/questionnaire.html',
controller: "QuestionnaireController as vm",
resolve: {
practice: function($http){
return $http
.get('https://.../...')
.then (function (data) {
return data;
});
}
}
})
.state('questionnaire.consent', {
url: '/consent',
templateUrl: 'templates/questionnaire-consent.html'
})
.state('questionnaire.questions', {
url: '/questions',
templateUrl: 'templates/questionnaire-questions.html',
resolve: {
questions: function($http, $scope) {
return $http
// Failed Attempts
// .get('https://.../questions', {params: {gender: $scope.user.gender}})
// .get('https://.../questions', {params: {gender: $scope.user.gender}})
// .get('https://.../questions', {params: {gender: user.gender}})
// .get('https://.../questions', {params: {gender: vm.user.gender}})
// Works but incorrectly hard coded
// .get('https://.../questions', {params: {gender: 'Male'}})
.then (
function (res) {
console.log(res.data);
return res;
},
function(errors) {
console.log('Errors', errors);
}
);
}
}
})