angularjs ui-router passing dynamic data from form field into resolve -


i trying use resolve in order ensure data has been loaded prior view state displaying on screen. resolve dependent on selection user have made in previous state.

as such, need perform request parameter.

the problem have no idea how set parameter within app. 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 thing works is:

.get('https://.../questions', {params: {gender: 'male'}})

bigger code snippet below give context.

 .state('questionnaire', {     url: '/questionnaire',     templateurl: 'templates/questionnaire.html',     controller: "questionnairecontroller 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 incorrectly hard coded    //      .get('https://.../questions', {params: {gender: 'male'}})            .then (             function (res) {               console.log(res.data);               return res;             },             function(errors) {               console.log('errors', errors);             }           );       }     }   }) 

use $stateparams service. lets pass parameters states, example can pass gender parameter:

.state('questionnaire.questions', {   url: '/questions/:gender', // gender parameter.   templateurl: 'templates/questionnaire-questions.html',   resolve: {     questions:  function($http, $scope, $stateparams) {       // $stateparams.gender gender given in url. 

you can give gender parameter when using href: example.com/questions/male or using second parameter of $state.go: $state.go('questions', {gender: 'male'});

read in ui-router documentation.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -