Angular: how to initialize textarea with default value

Ahmad Elmoualem

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>
shaunhusain

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angular textarea can't be filled with default value

From Java

How to add default value for html <textarea>?

From Dev

How to initialize a generic array with a default value in Scala

From Dev

How to initialize NumPy array with different default value for each column?

From Dev

How to initialize NumPy structured array with different default value for each column?

From Dev

How does the compiler initialize local arrays with a default value of zero on the stack?

From Dev

Default Value TextArea Mysterious Spaces

From Dev

Initialize variable with default value in python

From Dev

How to set default selected value in Angular Chosen?

From Dev

Default textarea value in angularjs when textarea is bound to model

From Dev

Get the default value of a textarea using Jquery

From Dev

Does std::array default-initialize or value-initialize?

From Dev

Fortran : Initialize all variables to a specific default value

From Dev

Can't initialize a struct with a default value

From Dev

Initialize a const class member with a default value

From Dev

Angular js directive : How to set selected value or default value

From Dev

CodeMirror How to get Textarea value

From Dev

CodeMirror How to get Textarea value

From Dev

How to clear a textarea value in jQuery?

From Dev

How to insert textarea value into database?

From Dev

How to enable wysiwyg by default on textarea in admin?

From Dev

how to initialize application asynchronously in angular

From Dev

How to initialize default float values in to array of structs?

From Dev

When and how to default-initialize a const variable?

From Dev

How to initialize database with default values in sqlalchemy?

From Dev

How to initialize a queue with n default values?

From Dev

How to initialize database with default values in sqlalchemy?

From Dev

How to initialize default float values in to array of structs?

From Dev

How to initialize default values in jQuery slider?

Related Related

  1. 1

    Angular textarea can't be filled with default value

  2. 2

    How to add default value for html <textarea>?

  3. 3

    How to initialize a generic array with a default value in Scala

  4. 4

    How to initialize NumPy array with different default value for each column?

  5. 5

    How to initialize NumPy structured array with different default value for each column?

  6. 6

    How does the compiler initialize local arrays with a default value of zero on the stack?

  7. 7

    Default Value TextArea Mysterious Spaces

  8. 8

    Initialize variable with default value in python

  9. 9

    How to set default selected value in Angular Chosen?

  10. 10

    Default textarea value in angularjs when textarea is bound to model

  11. 11

    Get the default value of a textarea using Jquery

  12. 12

    Does std::array default-initialize or value-initialize?

  13. 13

    Fortran : Initialize all variables to a specific default value

  14. 14

    Can't initialize a struct with a default value

  15. 15

    Initialize a const class member with a default value

  16. 16

    Angular js directive : How to set selected value or default value

  17. 17

    CodeMirror How to get Textarea value

  18. 18

    CodeMirror How to get Textarea value

  19. 19

    How to clear a textarea value in jQuery?

  20. 20

    How to insert textarea value into database?

  21. 21

    How to enable wysiwyg by default on textarea in admin?

  22. 22

    how to initialize application asynchronously in angular

  23. 23

    How to initialize default float values in to array of structs?

  24. 24

    When and how to default-initialize a const variable?

  25. 25

    How to initialize database with default values in sqlalchemy?

  26. 26

    How to initialize a queue with n default values?

  27. 27

    How to initialize database with default values in sqlalchemy?

  28. 28

    How to initialize default float values in to array of structs?

  29. 29

    How to initialize default values in jQuery slider?

HotTag

Archive