I built an app that showing messages, when the user press on edit
i want the message textarea
to be initialized with it's value i create a factory called notification
to get the message from my data base and in the controller i called this factory:
$scope.notification = notification.getNotification($stateParams.id);
$scope.notification.then(
function(notification) {
$scope.notification = notification;
console.log($scope.notification.message);
},
function(response) {
console.log('error fetching the notification', response);
}
);
and the HTML :
<textarea ng-model="item.message" class="form-control" ng-init="item.message={{notification.message}}"></textarea>
The textarea kept empty and this what i got in my elements inspector:
<textarea ng-model="item.message" class="form-control ng-pristine ng-untouched ng-valid" ng-init="item.message=hello"></textarea>
ng-init has one special use case with ng-repeat, see the ng-init documents for details on what it is meant to be used for.
You should just set the item.message to some value in your controller that is handling the scope for this section of the view. Basically set:
$scope.item = {message:$scope.notification.message};
or if $scope.item is already an object:
$scope.item.message = $scope.notification.message;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments