I created an application that displays messages, when the user clicks on edit, I want the message to textareabe initialized with its value. I create a factory called notificationto receive a message from my database 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 HTML:
<textarea ng-model="item.message" class="form-control" ng-init="item.message={{notification.message}}"></textarea>
The text box is left blank, and this is what I got in my item inspector:
<textarea ng-model="item.message" class="form-control ng-pristine ng-untouched ng-valid" ng-init="item.message=hello"></textarea>
source
share