2

Is it true that ngBind and ngModel are very similar: bind the model (the data) the either static text element or changeable element, such as text input box, select element, or textarea.

In that case, wouldn't it make sense, just to have one name, say ngModel, and let it work for all elements (and so we don't need ngBind)?

This almost feels like polymorphism, with which, ngModel has one behavior for changeable element and another behavior for unchangeable elements.

1

3 Answers 3

1

Well, it's a design decision. No more, no less.

Other libraries like ractivejs go even one step further: no need for ngBind/ngModel, everything are just mustaches:

<h1>{{title}}</h1>
<input value="{{foo}}" />

And they'll automatically be two way data bound for inputs, selects, textareas and other interactive components.

0

ng-bind is one way data binding used for displaying the value inside html component as inner HTML. This directive can not be used for binding with the variable but only with the HTML elements content. This directive is very useful for updating the blocks like div, span, etc. with inner HTML content.

While ng-model directive in AngularJS works as two way data binding.

e.g: If you want to understand better about the two way bindings, you have an input component and the value updated into that field must be reflected in other part of the application. The better solution is to bind a variable to that field and output that variable whereever you wish to display the updated value throughoput the application.

For better understanding See here...

1
  • Both links appear to be broken. Aug 11, 2016 at 4:03
0

ngModel and ngBind don't serve the same purpose.

ngBind same the same purpose than the brack notation : {{something}}.

It's usage permit to not have bracket notation so you won't have an ugly template with lots of brackets flickering.

ngModel is used for every directive that need two-way binding and use the ngModelController (so you can customise, formatting, parsing, validation). That what does the directives input, select, textarea.

TL;DR : use ng-bind instead of {{}}, use ng-model in forms fields, and directives that requires it. As for why ng-bind don't work in input,... see @Surjeet Bhadauriya's answer.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.