I am an AngularJS newbie and trying to figure out what class=ng-binding
does in this example:
<label ng-dblclick="editTodo(todo)" class="ng-binding">fghfgh</label>
I found it here:
http://todomvc.com/architecture-examples/angularjs/#/
I use Chrome and developer tools. Is this an angular keyword? I could not find it in the manual (http://docs.angularjs.org/api/ng.directive:ngBind)
The ng-bind directive tells AngularJS to replace the content of an HTML element with the value of a given variable, or expression. If the value of the given variable, or expression, changes, the content of the specified HTML element will be changed as well.
ngModel usually use for input tags for bind a variable that we can change variable from controller and html page but ngBind use for display a variable in html page and we can change variable just from controller and html just show variable.
The ng-bind Directive in AngularJS is used to bind/replace the text content of any particular HTML element with the value that is entered in the given expression. The value of specified HTML content updates whenever the value of the expression changes in the ng-bind directive.
ng-bind directive binds the AngularJS Application data to HTML tags. ng-bind updates the model created by ng-model directive to be displayed in the html tag whenever user input something in the control or updates the html control's data when model data is updated by controller.
class="ng-binding"
is used internally by Angular. For example, looking at the ngBind
source we find this line that adds the class and associates the binding with it using .data
:
element.addClass('ng-binding').data('$binding', attr.ngBind);
That's why this line of Angular source (noting the double curlys on {{todo.title}}
result in an ngBind
):
<label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
Is translated into what you see in the debugger:
<label ng-dblclick="editTodo(todo)" class="ng-binding">fghfgh</label>
So class="ng-binding"
isn't something you should use. You'll find Angular frequently uses classes, comments and other markers- so you'll often see this kind of change between the original html and the Angular processed results.
From the docs:
ng-binding
Usage: angular applies this class to any element that is attached to a data binding, via ng-bind or {{}} curly braces, for example. (see databinding guide)
So the class ng-binding
is applied by angular dynamically, for the compiler to understand that, element has a data binding associated with it.
As a developer we don't have to worry about that unless we apply some styles to these classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With