Reputation: 2084
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 :
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.
Upvotes: 0
Views: 76
Reputation: 61
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
.
Upvotes: 1