In the context of the angular document discussion, the term "model" can be applied to a single object representing an entity (for example, a model called "phones" whose value is an array of telephones.) Or as the application of all data model (all entities).
In angular, model can be arbitrary data and can be obtained by angular the properties of the scope object. The name of the property is the identity of model, and the value can be any JavaScript object (including arrays and raw data).
The only condition that JavaScript wants to be model is that objects must be angular scope references as properties of a scope object. A reference relationship to a property can be created either explicitly or implicitly.
There are several ways we can explicitly create a scope property, associating a JavaScript object to create model:
In JavaScript code, a property that is assigned directly to a scope object; This is usually emitted in the controller now:
function Myctrl ($scope) {
//create property ' foo ' on the Myctrl ' s scope
//and assign it a initial value ' bar '
$scope. foo = ' bar ';
}
In the angular expression (http://www.cnblogs.com/lcllao/archive/2012/09/16/2687162.html) of the template, use the assignment operator:
<button ng-click= "{{foos= ' ball '}}" >click me</button>
Use nginit directive (Http://docs.angularjs.org/api/ng.directive:ngInit) in templates (only as an example, not recommended for real applications)
<body ng-init= "foo = ' Bar '" >
Angular will implicitly create model in the following template structure:
Input, select, textarea, and other form elements of the form:
<input ng-model= "Query" value= "Fluffy Cloud" >
The code above creates a model called "query" in the current scope and binds to the value value of input, initialized to "fluffy cloud".
Declaring iterators in Ngrepeater
<p ng-repeat= "Phone in Phones" ></p>
The above code creates a child scope for each element of the phones array, and creates "phone" model in the corresponding child scope, giving the corresponding value in the array.
In angular, the JavaScript object will no longer be a model when the following situation occurs:
When there is no angular scope that contains the properties associated with the object.
All angular scopes that contain properties associated with objects become obsolete and appropriate for garbage collection.
The following illustration shows the implicit creation of a simple data model in a simple stencil.
above is about Angularjs understanding the Model Component data collation, follow-up continue to add, thank you for your support of this site!