0

I have a call in controller

vm=this;
User.query()
  .$promise
  .then(function(resp){
    `vm.response = resp` 
  });

in if

if(!!$stateParams.id){`console.log(vm.response.id);`
}

For edit page I got id undefined. User.query get called after this if. For create it works ok.

Mohit Tanwani
  • 6,608
  • 2
  • 14
  • 32
G. K.
  • 29
  • 5
  • What's with the backticks? – Phil Sep 01 '16 at 06:58
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Phil Sep 01 '16 at 07:00
  • yes seams to be duplicate of http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Jekin Kalariya Sep 01 '16 at 07:00
  • You can use $stateChangeStart for that. – Niels Steenbeek Sep 01 '16 at 07:01
  • @Phil backsticks are a ES6 feature to define multiline strings. – illeb Sep 01 '16 at 07:19
  • @Luxor001 yes, I know that but they don't make sense where OP is using them. I assume they just messed up trying to format the code in the question but was confused because it's only applied to those two lines. Will need OP to clean it up – Phil Sep 01 '16 at 07:21
  • Ah i see, yeah i agree with you, probably OP messed up the code – illeb Sep 01 '16 at 07:23
  • hi, I'm new on stack overflow, I don't get what is OP – G. K. Sep 01 '16 at 12:25

0 Answers0