Module
So far, define a way to use the angular app ng-app="" .
Yes, but the variables and functions under this app are global and can cause controller pollution (pollute).
In general, we use the module to organize the app. We can ng-app="名称" angular.modele() declare a module by or.
The method has two parameters:
- The name of the module
- Dependency List
For example, the previous example could be changed to:
<div ng-app="myApp" ng-controller="fighterController"> <script> var myApp = angular.module("myApp",[]); myApp.controller("fighterController", function($scope) { //.. } </script></div>
If you put the app and controller into two files defined separately, then:
<div ng-app="myApp" ng-controller="fighterController"> <script src="myApp.js"></script> <script src="myAppControllers.js"></script></div>
Myapp.js:
var myApp = angular.module("myApp",[]);
Myappcontrollers.js:
myApp.controller("fighterController", function($scope) { //..}
Filter
This can be added to the expression, changing the output format of the expression.
We can use the following filters:
| Filter |
Description |
| Uppercase |
Turn capital |
| lowercase |
Turn lowercase |
| Currency |
Turn currency format |
| By |
Sort by specified attribute |
| Filter |
Filter by the specified keyword |
The first 3 can be used directly in an expression, such as:
{{name | uppercase}}{{name | lowercase}}{{total | currency}}
Filter and by-do are typically used for arrays:
<div ng-app="" ng-controller="fighterController"> <input ng-model="search"/> <ul> <li ng-repeat="f in fighters|filter:search"> {{ f }} </li> </ul> <script> function fighterController($scope) { $scope.fighters = [ {name:‘Ryu‘,country:‘Japan‘}, {name:‘Ken‘,country:‘USA‘}, {name:‘Chun Li‘,country:‘China‘}, {name:‘GuiLe‘,country:‘USA‘}, {name:‘Zangief‘,country:‘Russia‘} ]; } </script></div>
Of course, the data will not be placed in a controller.
We can $http request the data and bind it.
The above example can be changed to:
function fighterController($scope,$http) { var url = ‘请求地址‘; $http.get(url).success(function(response) { $scope.fighters = response; })}
AngularJS-Quick Start