I have learned about the basic usage of AngularJS before, so here I will learn the relevant content of expressions with PDF.
Expressions in AngularJS are not exactly the same as in js.
First of all, its expression must be placed in {{}} before it can be used. Secondly, compared with the expression concept in javascript, it has the following differences:
1 Different scopes
The default function in javascript is window, but it is different in angularJs. It uses $scope control to act on.
2 Allow undefined values
In angularjs, if an undefined expression is used, there will be no error, and the null value will be returned directly.
3 filters
You can use the | pipe command character in an expression to add filters, similar to UNIX's command line.
4 $ symbol
Used to distinguish angular methods from user-defined methods.
Here is a small code:
<!doctype html><html ng-app> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script> </head> <body> <div ng-controller="ctl"> name:<input ng-model="name" type="text"> <button ng-click="reset()">reset</button> <br> {{name}} <br> hello ! {{test}} <br> filter : {{name | uppercase}} </div> <script type="text/javascript"> function ctl($scope){ var str = "init"; $scope.name = str; $scope.reset = function(){ $scope.name = str; } } </script> </body></html>trigger the reset method through reset to reset the content of the name variable;
In the expression, an undefined test is referenced, but no error is reported, and it is displayed as empty by default; - {{test}}
Finally, use a filter to convert the value of name in the expression to uppercase. ― {{name | uppercase}}
Running results:
The above is the information sorting out the AngularJS expressions. We will continue to add relevant information in the future. Thank you for your support!