0

I have a text input in a form that I want to fill with data I'm getting from a promise.

this is my text input :

<input type="text" name="lastname" id="lastname" class="form-control input-lg"
ng-model="candidature.lastname"
required>

And In my controller I have this :

candidatureService.get({id: $rootScope.username}).$promise.then(function (res) {

      $scope.candidature = {};
      $scope.candidature.lastname = res.nom;

//code...

}).catch(function (err) {
      console.log('Error getting data');
});

When I inspected my application using batrang I can see that the object candidature in $scope has the value I'm getting using that promise :

enter image description here

And as you can see I have ng-model="candidature.lastname".

Does anyone know why the text input doesn't get the value from the scope?

Thanks in advance.

3
  • Assign your response data to canditure first like $scope.candidature = res; then you will get the value on form. Commented Apr 27, 2016 at 10:15
  • @Abhishekkumar if I did that I'll have something like this $scope.candidature.nom instead which will not work since I want to fill $scope.candidature.lastname and not $scope.candidature.nom Commented Apr 27, 2016 at 10:20
  • Declare this $scope.candidature = {}; before the service request then as it is making things blank thus you dont have output on screen Commented Apr 27, 2016 at 10:25

1 Answer 1

1

Try declaring $scope.candidature = {}; before you make the API request...

But from the code it looks like you have only declared $scope.candidature.lastname and not $scope.candidature.firstname.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks that was the problem, I had to declare the object candidature outside the api request for $scope.candidature.lastname it was just an error in typing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.