| Start |
|---|
| $digest and $watch Implementing two-way-data-binding, to achieve the result from the previous example, could be done with two core functions:
note: this is example is a demonstration, not the actual angular code The two functions we need: Now we could now use these functions to hook up a variable to the DOM (angular comes with built-in directives which will do this for you): Off-course, the real implementations are more complex, and support parameters such as which element to bind to, and what variable to use A running example could be found here: https://jsfiddle.net/azofxd4j/ (opens new window) |
| the $scope tree The previous example is good enough when we need to bind a single html element, to a single variable. In reality - we need to bind many elements to many variables: This The way angular achieves this behavior is using a separate context for each element which needs separate variables. This context is called a scope. Each scope contains properties, which are the variables bound to the DOM, and the The DOM is a tree, and variables need to be used in different levels of the tree: But as we saw, the context(or scope) of variables inside Each scope has an array of children, and calling its This way - after changing the input - A simple implementation for a scope, could look like this: note: this is example is a demonstration, not the actual angular code |
| two way data binding Angular has some magic under its hood. it enables binding DOM (opens new window) to real js variables. Angular uses a loop, named the "digest loop", which is called after any change of a variable - calling callbacks which update the DOM. For example, the Every time the At some point, the digest loop iterates over a callback which updates the contents of this span: The basic life-cycle of this example, summarizes (very Schematically) how angular works::
Syntax
|
Read Article
https://develop.horje.com/learn/1434/reference