5

HTML:

<textarea ng-model="user.ban_reason"></textarea>

Initially the ban reason is empty. However I want to provide a default value. But

<textarea ng-model="user.ban_reason">reason</textarea>

Does not work.

Any ideas how to do that?

1
  • 1
    How about using a placeholder? -- jsfiddle.net/Xxqnr/2 Commented Aug 14, 2013 at 13:23

3 Answers 3

8

Inside your controller you can do as below:

$scope.user = {
    ban_reason:"reason"
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hm actually I don't wont to do this in controller, we should keep this in view. Any idea how to do this in view?
Your view should not contain any data. If you just want to hint/guide the user, use a placeholder as tymeJV suggested in the OP comments.
5

Well if there is a situation you still need it to have default text in the template, then you can use ng-init.

  <textarea ng-model="text" ng-init="text = 'Hello, this is my default text.'"></textarea>

Comments

4

Your angular app initializes when the documents DOM is ready - thus, overrides the value with your $scope.user.ban_reason value.

In your controller, define a default value for the model property:

$scope.user = { ban_reason: 'reason' };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.