Home  >  Article  >  Web Front-end  >  How to use AngularJS1.0? Details of how to use angularjs (with principles)

How to use AngularJS1.0? Details of how to use angularjs (with principles)

寻∝梦
寻∝梦Original
2018-09-08 16:05:092764browse

This article mainly talks about the introduction of knowledge about angularjs1.0, which can be regarded as a summary of its use. I believe that after reading this article about angularjs, you may realize some of its benefits. Now let’s look at this article

Today we will continue to talk about the knowledge of Angular1.0. In the above section we talked about two aspects of this framework. In fact, today I want to talk about the knowledge of MVC. Be more thorough.

1. The framework of the mvc pattern

Why is the design idea of ​​mvc needed: Because The amount of code in the front section is getting larger and larger, and it is increasingly important to separate it and collaborate with each other. In addition, we have a large amount of reusable code. In order to solve the above problems, the mvc mode was introduced. mvc is just a means, the real purpose is modularization and code reuse.

Let’s talk about MVC now. First we must know


  • # Model - A minimum level responsible for maintaining the data schema.

  • View/View - The part responsible for displaying all or data to the user.

  • ##Controller/Controller - software code controls the interaction between Model and View

  • How to use AngularJS1.0? Details of how to use angularjs (with principles)

  • How to use AngularJS1.0? Details of how to use angularjs (with principles)

  • #The implementation and principle of public two-way data can be built

##As mentioned above, combine the following code

How to use AngularJS1.0? Details of how to use angularjs (with principles)

The ng-model in the code is bound to the attribute of $scope: name, and is bound to the article information through expressions. The next step is to detect changes in real time. This function is already built into AngularJS.

Working principle: The HTML web page contains AngularJs instructions and expressions, which will eventually be compiled by the AngularJs compilation mechanism and attached to the DOM tree. AngularJs directives can be freely extended by us. In AngularJs as an MVC framework, we do not need to add dom-level event listeners in the controller, These are already built-in in AngularJs. View objects can be used by AngularJs The Scope reference can be any type of javascript object, array, primitive type, object. And AngularJs will automatically update the model asynchronously, that is, it will automatically refresh the model (mode) when the view layer changes, and conversely, it will automatically refresh the view layer when the model changes. We don't need to define other methods here. This is the embodiment of the MVC idea of ​​AngularJs. (If you want to see more, go to the PHP Chinese website AngularJS Development Manual to learn)

Multiple controllers in this , multiple views can be controlled without interfering with each other. Of course, the $scope objects under their respective controllers also have their own scopes. This makes the respective controls independent of each other and facilitates many operations. In the controller part, the public root control $rootscope can be used to transfer values ​​between subsets . We can also make part of the public code into a service, so that we can later inject this AngularJs Features can be placed in the required controller and then called, which greatly facilitates the reusability of the code. That’s it for today. The next one will talk about instructions and dependency injection. Slowly understand AngularJs thoroughly.

This article ends here (if you want to see more, go to the PHP Chinese website AngularJS User Manual). If you have any questions, you can leave a message below. Ask questions.

The above is the detailed content of How to use AngularJS1.0? Details of how to use angularjs (with principles). 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