In this ng-init
would result into inappropriate behavior, if user
object is loaded from API
service call, the ng-init
directive fires before than that. So dnameform
value will be always undefined
.
Rather I believe you should directly use user.user_displayname
as in ng-model
no need of creating new ng-model
variable.
<input ng-model="user.user_displayname" type="text">
And wherever you need a value, you can directly use $scope.user.user_displayname
OR
You can do assignment of dnameform
variable from controller, when user API service call finishes off. Then you're free to use dnameform
as in ng-model
on input field without ng-init
.
apiService.getUser().then(function(res){
$scope.user = res.data
$scope.dnameform = user.user_displayname;
})