Angular: how to initialize textarea with default value

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>
+4
source share
1 answer

ng-init has one special use case with ng-repeat, see the ng-init docs for details on what it is intended for use with.

item.message - , . :

$scope.item = {message:$scope.notification.message};

$scope.item :

$scope.item.message = $scope.notification.message;
0

All Articles