totothegreat
totothegreat

Reputation: 1643

ng-model on textarea issue in angular?

I'm trying to do a simple thing, and it doesn't seem to work for some reason...

<textarea name="description" ng-model='model.feed.description' class='text-area-input-style' ng-maxlength='6' ng-required='true'>
{{model.feed.description}}
</textarea>

No matter what i do, i can't see the text whithin the textarea...

Only if i exclude the ng-model from the textarea tag:

  <textarea name="description" class='text-area-input-style' ng-maxlength='6' ng-required='true'>
    {{model.feed.description}}
    </textarea>

I can see the text of my model, but it's not the behaviour i want... what is the problem here?

Upvotes: 0

Views: 833

Answers (1)

Erik Honn
Erik Honn

Reputation: 7576

Two things come to mind. How to bind and the fact that your descriptions is probably to long.

Like richardtz said in the comment you only need ng-model, inserting the value directly into the textarea with {{}} is not what you want. ng-model will bind the field to your model so that it shows the initial value and it updates when the user changes it. Doing only {{}} like in your second example will just insert then value there, not creating a binding.

Secondly, ng-maxlength will block you if the value is too long. If model.feed.description is longer than 6 characters, it won't be shown, but this only applies if you use a databidning like ng-model, not when just inserting a value. This is probably why it is working in the second case.

Upvotes: 3

Related Questions