Problems with ngModel required in directive

Asked

Viewed 153 times

0

I’m having a problem with my directive, she gets one ngModel to insert a value that exists in a text field within it, but when that model already comes with some value it simply disappears with it.

Basically what I want is to pass the ngModel for my directive, if there is any value in the model it insert in the text field, and any modification of the field it modify in the model.

1 answer

1

You don’t need a directive for that to happen.
Angularjs has a two-way-data-Binding concept.
When you place ng-model in your text field and declare the variable with the same name in your module, any change you make on one side reflects on the other.

By default, for each element declared with ng-model in your view, the angular creates a $Scope. $watch() for this element that monitors any change in it and reflects on the other side.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.