?
1. Boot program
?
Start booting a program with Ng-app: tags the scope of the Angularjs app
- <!doctype html>
- <htmllang= "en"ng-app>
Double-brace Binding expression:
- <p>nothing here {{' yet ' + '! '}} </P>
?
2. Views and templates
?
The core is the MVC pattern
Principle: In Angularjs, a view is a map after the model is rendered through an HTML template
?
HTML Templates :
Contains Ng-controller directives, and ng-repeat directives
- <htmlng-app>
- <head>
- ?? ...
- ?? <scriptsrc= "lib/angular/angular.js" ></script>
- ? ? <scriptsrc= "js/controllers.js" ></script>
- </head>
- <bodyng-Controller= "Phonelistctrl">
- ?
- ?? <ul>
- ???? <ling-repeat= "phone in phones">
- ?????? {{Phone.name}}
- ???? <p>{{phone.snippet}}</p>
- ???? </li>
- ?? </ul>
- </body>
- </html>
Ng-repeat Syntax: object variable in object array
?
Models and controllers :
$scope is a scope, a successor to the root scope, which is used by the name of Di.
Phones is the model.
- function Phonelistctrl ($scope) {
- ?? $scope. Phones = [
- ???? {"Name": "Nexus S",
- ?????" Snippet ":" Fast just got faster with Nexus S. "},
- ???? {"Name": "Motorola XOOM?") With Wi-Fi ",
- ?????" Snippet ":" The next, next Generation tablet. "},
- ???? {"Name": "MOTOROLA XOOM?",
- ?????" Snippet ":" The next, next Generation tablet. "}
- ??];
- }
?
The scope theory of Angularjs is very important:
- A scope can be seen as a glue that works together as a template, model, and controller.
- Angularjs uses scopes, as well as information in templates, data models, and controllers.
- These can help separate the model from the view, but they are really synchronous! Any changes to the model are immediately reflected in the view, and any changes to the view are immediately reflected in the model.
?
3. Filter
?
Conditional filtering on the page:
Search: <input ng-model= "Query" >
?
- <ulclass= "Phones" >
- ???????? <ling-repeat= "Phone in phones | filter:query" >
- ?????????? {{Phone.name}}
- ???????? <p>{{phone.snippet}}</p>
- ???????? </li>
- </ul>
?
Explain:
?
4. Bidirectional binding
?
Use Orderprop as a model binding whose value is applied to the filter and used as a sort
Orderby:orderprop: Sort by the attributes selected by Orderprop.
- <selectng-model= "orderprop" >
- ?? <optionvalue= "Name" > Alphabetical</option>
- ?? <optionvalue= "Age" > Newest</option>
- </Select>
- ?
- ?
- <ulclass= "Phones" >
- ?? <ling-repeat= "Phone in phones | filter:query | orderby:orderprop">
- ???? {{Phone.name}}
- ???? <p>{{phone.snippet}}</p>
- ?? </li>
- </ul>
?
Initialization
$scope. Orderprop = ' age ';
?
5. XHR and Dependency Injection
?
A series of objects that begin with di:$. such as: $scope, $http.
- function Phonelistctrl ($scope, $http) {
- ?? $http. Get (' Phones/phones.json '). Success (function (data) {
- ???? $scope. phones = data;
- ??});
- ?
- ?? $scope. Orderprop = ' age ';
- }
?
To avoid compressing the di:
- Phonelistctrl. $inject = [' $scope ', ' $http '];
?
Another method:
- var Phonelistctrl = [' $scope ', ' $http ', function ($scope, $http) {/* Constructor body */}];
?
6. Links
?
ng-src= "{{Phone.imageurl}}" >
?
7. Routing and Multi-view
?
Angular JS Notes