Share detailed examples related to Angularjs

零下一度
Release: 2017-07-03 14:14:55
Original
1015 people have browsed it

I stayed at home for two days this weekend, and I continued to share Angularjs-related content during my free time at noon. Today I will mainly share the general introduction to Angularjs and the data binding part. Let’s go directly to the topic.

1. Basic concepts:
AngularJS is designed to overcome the shortcomings of HTML in building applications. HTML is a good declarative language for pseudo-static text display design, but it is weak when it comes to building WEB applications. So I did some work (you can also think of it as a little trick) to make the browser do what I want. Usually, we use the following technologies to solve the shortcomings of static web page technology in building dynamic applications.
2. Version

Angualrjs1.x: Currently a relatively stable version.
angularjs2.x: written based on typescript, it has changed a lot on the basis of 1.x and is biased towards mobile development. It is written in ES6 standards
Angularjs4.x latest version

The current version is 2.x It is not an upgrade based on 1. It advocates componentization, which is similar to Vue and React.

3. Core features
MVC (or MVVM) design idea:

Many people will think of Angularjs It is a front-end MVC framework. I think MVC is just a design idea. I think it can be said that there is a shadow of MVVM in it, because MVVM is upgraded on the basis of MVC and adds a two-way data binding function, but this is just my personal opinion. Please correct me, gods.

Two-way data binding:

Two-way data binding was not proposed by AngularJs. It existed very early. Microsoft’s WPF uses MVVM ideas and front-end frameworks. Knockoutjs has the concept of two-way binding of data.
Modularization and Dependency Injection

Modularization and dependency injection are the core content of AngularJs and the highlight of Angular.
Command system

The command system is also the core of Angular. The command system is divided into built-in commands and custom commands. Among them, I think the function of custom commands is very powerful and can achieve many powerful functions. Functions and details will be explained in detail when explaining the instructions.

4. Areas of expertise

1) Single Page Application (SPA)
2) CRUD program

It is possible that some gardeners may not understand single-page applications very well. To give a simple example, for example, our traditional multi-page application MPA through the Iframe framework has the disadvantage of loading multiple pages multiple times. Single-page applications are loaded or switched through Html segments. I won’t introduce too much about MPA and SPA here. You can understand them by Baidu.

AngularJs is suitable for CRUD application systems, but it is not suitable for applications with frequent page interactions or graphical pages and game systems are not suitable for this framework.

5. AngularJs application composition

Any ng application is composed of module types such as controllers, services, instructions, routes, filters, etc. Composition, let me use a diagram to represent the relationship:

6. Module
In AngularJS Module is a core existence, including many aspects, such as controller, config, service, factory, directive, constant, etc.
How to create the module:
angular.module('myApp',[]);
How to use the module:
Add ng-app where needed (on a certain HTML tag)
Benefits of using modules:
1) Keep the global namespace clean;
2) Easier to write test code;
3) Easy to reuse code between different applications.
4) Use declarations to make it easier to understand.

7. Using AngularJs in the application

1) When using Angular in the application, first reference the js library code of the angular framework in the page .

  首页   
Copy after login

 2) Add the ng-app module to the html element that applies Angular scope. If you need to add a controller, add ng-controller. This is not necessarily on the body element, it can be arbitrary. On the element, this indicates the application boundary using Angular.

  

{{expression}}

{{ngmodel}}

Copy after login

 3. Add js code and define modules and controllers

Copy after login

From the above code snippet, you can see how to define the module and controller methods, and the meaning of each parameter is commented. You can take a look.

The source code will be shared with everyone on GitHub at that time, and everyone can download it.

I will share as much content with you today. Next time I will share with you data binding and controller-related content. Thank you all for your support, and you are welcome to correct me if there is anything wrong!

The above is the detailed content of Share detailed examples related to Angularjs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!