Summary of common knowledge for getting started with AngularJS
巴扎黑Original
2017-07-23 15:07:361462browse
Preface
Let’s learn about AngularJS with you today...
AngularJS uses new attributes and expressions The format extends HTML.
AngularJS can build a single page application.
AngularJS is very easy to learn.
## 1. AngularJS instructions and expressions
【AngularJS common instructions】 1. ng-app: declare that Angular is governed area is generally written on the body or HTML. In principle, there is only one on a page. 2. ng-model: Bind the element value (such as the value of the input field) to the application variable. #eg: 3. ng-bind: Put the Data is bound to the HTML view and can be replaced by expressions. eg:
is equivalent to
{{name}}
4. ng-init: Initialize AngularJS application variables. eg: 5. Expression: {{} }Bind expression, which can contain literals, operators and variables. But the expression will see {{}} when the web page is loaded, so you can use ng-bind="" instead. eg:{{ 5 + "" + 5 + ',Angular' }}
[Basic concepts] Directive: In AngularJS, functionality is provided by extending HTML attributes. Therefore, the new attributes starting with ng- are called instructions by us.
# 2. Scope in MVC in AngularJS
[MVC three-tier architecture] 1. Model: The part of the application used to process data. (Save or modify data to database, variables, etc.). Model in AngularJS specifically refers to: data. View (View): The page that the user sees for displaying data. Controller: The part of the application that handles user interaction. Responsible for reading data from the view, controlling user input, and sending data to the model.
2. Working principle: The user sends a request from the view layer. After receiving the request, the controller forwards it to the corresponding model for processing, and returns after the model processing is completed. The result is given to the controller and fed back to the user at the View layer.
3. Create an Angular module, which is the part bound by ng-app. Two parameters need to be passed: ①Module name: the name that ng-app needs to be bound to, ng-app="myApp" ②Array: the name of the module that needs to be injected, not required null. eg:var app= angular.module("myApp",[]);
On the Angular module, create a controller Controller, required Pass two parameters. ①Controller name, that is, the name that ng-controller needs to be bound to. ng-controller="myCtrl" ②Controllerd's constructor: The constructor can pass in multiple parameters, including $scope/$rootScope and various system built-in objects;
[Scope in AngularJS] ①$scope: local scope, properties and methods declared on $scope can only be used in the current Controller ②$rootScope: Root scope, properties and methods declared on $rootScope, can be used in any area included in ng-app (whether with Controller or not, Or whether it is in the scope of the Controller)
##>>>If $scope is not used to declare variables, and the variable scope bound using ng-model directly in HTML is : 1. If ng-model is in an ng-controller, this variable will be bound to the $scope of the current Controller by default; 2. If ng-model is not in any ng-controller, this variable will be bound to $rootScope.
##3. AngularJS filter
In AngularJS, filters can be added to expressions and directives using a pipe character (|).
>>>System built-in filter: currency: Format numbers into currency format. filter: Select a subset from array items. lowercase: Format the string to lowercase. orderBy: Arrange the array according to an expression. uppercase: Format the string to uppercase.
1. http in AngularJS $http is a core service in AngularJS, used to read data from remote servers.
2. Select in AngularJS ① Use an array as the data source, where x represents each item of the array. By default, x will be directly bound to the value of option, and the content displayed by option is determined by the previous x for.... eg:
② Use objects as data sources, where (x, y) represents key-value pairs, x is the key and y is the value. By default, the value y will be bound to the value of option, and the content displayed by option is determined by the previous x for.... eg: section>
3. DOM operations in AngularJS ①ng-disabled="true/false" When passing When true, the control is disabled. When false is passed in, enabled.
Do you agree Xiaoxi is so cute!
②ng-show Displayed by default when true is passed in
Whether show?
③ng-hide Default Show that the incoming true is hidden
Is it hidden?
##④ng-click defines the click event in AngularJS . Only properties and methods bound in the Angular scope can be triggered.
{{ count }}
The above is the detailed content of Summary of common knowledge for getting started with AngularJS. For more information, please follow other related articles on the PHP Chinese website!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn