This article mainly talks about the explanation of expressions of angularjs, as well as the application details of angularjs. Let’s take a look at this article now
AngularJS expression is written within double curly brackets:{{ expression }}.
AngularJS expressions bind data to HTML, which is similar to the ng-bind directive.
AngularJS will "output" data where the expression is written.
AngularJS expressions are much like JavaScript expressions: they can contain literals, operators, and variables.
Example {{ 5 5 }} or {{ firstName " " lastName }}
Similar to JavaScript expressions, AngularJS expressions can contain letters, operators, and variables.
Unlike JavaScript expressions, AngularJS expressions can be written in HTML.
Unlike JavaScript expressions, AngularJS expressions do not support conditional judgments, loops and exceptions.
Unlike JavaScript expressions, AngularJS expressions support filters.
AngularJS directives are prefixed with ng HTML attributes.
AngularJS Module defines the AngularJS application.
AngularJS Controller (Controller) Used to control AngularJS applications.
ng-app directive defines the application, ng-controller defines the controller.
<p ng-app="myApp" ng-controller="myCtrl"> 名: <input type="text" ng-model="firstName"><br> 姓: <input type="text" ng-model="lastName"><br> <br> 姓名: {{firstName + " " + lastName}} </p> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; }); </script>
AngularJS module definition application:
var app = angular.module('myApp', []);
AngularJS controller control application:
app.controller('myCtrl', function($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; });
Application resolution:
AngularJS applications are defined by ng-app. The application runs within
.
ng-controller="myCtrl" attribute is an AngularJS directive. Used to define a controller.
The myCtrl function is a JavaScript function.
AngularJS uses the $scope object to call controllers.
In AngularJS, $scope is an application object (belonging to application variables and functions).
The controller's $scope (equivalent to scope, control scope) is used to save AngularJS Model objects.
The controller creates two properties (firstName and lastName) in the scope. The
ng-model directive binds the input fields to the controller's properties (firstName and lastName).
Okay, this article ends here (if you want to see more, go to the PHP Chinese website AngularJS User Manual to learn). If you have any questions, you can leave a message below.
The above is the detailed content of How much do you know about AngularJS expressions? Detailed explanation of angularjs expressions and applications (refined version). For more information, please follow other related articles on the PHP Chinese website!