Getting started with Angularjs basics_AngularJS
Regarding this, I actually don’t know who I should target or where to start writing, so here I will start writing according to a simple idea
1.angular.element
2.angular.Bootstrap
We know very well that when ng-app is applied to a node, angular will automatically initialize it for you. The initialization process is divided into the following steps
1. Angular will automatically initialize during document load. It will first find the node specified by the ng-app instruction.
2. Load module-related instructions
3. Create an injector (dependency manager) related to the application
4. With the specified ng-app as the root node, start compiling the Dom
Now let’s initialize it ourselves and make something equivalent to the ng-app command. angular.element is a wrapper that wraps original DOM elements or HTML strings as jQuery elements. angular.Bootstrap can manually initialize the script. We use these two to initialize this script
This is outside ng-app~~{{1 2}}
2.compiler
We clearly see that the official documents of angularjs are all camel case nomenclature, such as ngApp, ngModule, ngBind, etc. These are related instructions. The html compiler allows us to define element attributes and tags ourselves. Angular will These additional behaviors are called directives.
The official documentation explains the compiler as follows
Compiler
Compiler is an Angular service which traverses the DOM looking for attributes. The compilation process happens in two phases.
Compile: traverse the DOM and collect all of the directives. The result is a linking function.
Link: combine the directives with a scope and produce a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model. This makes the scope model the single source of truth.
Some directives such as ng-repeat clone DOM elements once for each item in a collection. Having a compile and link phase improves performance since the cloned template only needs to be compiled once, and then linked once for each clone instance.
Compiler is a service of Angular, responsible for traversing DOM nodes and searching for attributes. Compilation is divided into two stages:
1. Compile: traverse the nodes and collect all directives, and return a linking function
2. Link: Bind directives to a scope and create a live view. Any changes in the scope will be reflected in the view (updating the view); any user activity (change) on the template will be reflected in the scope model (two-way binding). This allows the scope model to reflect the correct values.
Some directives, such as ng-repeat, will copy a specific element (combination) once for each element in the collection. The two stages of compilation and linking improve performance. Because the cloned template only needs to be compiled once and then linked once for each element in the collection (similar to template caching).
3. Create your own directive step by step
1. Understand directive
First of all, understand that directives follow camel case naming, such as ngModule. When compiled, the matching is like this, for example:
directive can use x- or data- as the prefix, and can use delimiters such as:, -, or _ to convert camel case naming methods, as shown below:
Generally we use ng-bind to correspond to ngBind, this format
$compile can match directives based on element names, attributes, class names and comments
During the compilation process, the compiler matches embedded expressions (such as {{something}}) in text and attributes through the $interpolate service. These expressions will be registered as watches and updated as part of the digest cycle. Here is a simple interpolation:
Hello {{username}}!
2. Compilation steps
Three steps of HTML "compilation":
1. First, convert HTML into DOM objects through the browser’s standard API. This is an important step. Because the template must be parsable (conforming to the specification) HTML. This can be compared with most template systems, which are generally based on strings rather than DOM elements.
2. Compilation of the DOM is completed by calling the $comple() method. This method traverses the DOM and matches the directive. If the match is successful, it will be added to the directive list together with the corresponding DOM. As long as all directives associated with the specified DOM are identified, they will be sorted by priority and their compile() functions will be executed in this order. The compile function of the directive has an opportunity to modify the DOM structure and is responsible for generating the parsing of the link() function. The $compile() method returns a combined linking function, which is a collection of linking functions returned by all directive's own compile functions.
3. Connect the template to the scope through the linking function returned in the previous step. This in turn calls the directive's own linking function, allowing them to register some listeners on the element and set up some watches in conjunction with the scope. The result is a two-way, instant binding between the scope and the DOM. When the scope changes, the DOM will get the corresponding response.
var $compile = ...; // injected into your code
var scope = ...;
var html = '';
// Step 1: parse HTML into DOM element
var template = angular.element(html);
// Step 2: compile the template
var linkFn = $compile(template);
// Step 3: link the compiled template with the scope.
linkFn(scope);
ngAttr attribute binding
That’s all for today, and I’ll start writing and creating the directive tomorrow ~~~ Don’t keep the length too long, there are many main concepts in this chapter~~~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is a widely used open source server-side scripting language that can handle all tasks in web development. PHP is widely used in web development, especially for its excellent performance in dynamic data processing, so it is loved and used by many developers. In this article, we will explain the basics of PHP step by step to help beginners from getting started to becoming proficient. 1. Basic syntax PHP is an interpreted language whose code is similar to HTML, CSS and JavaScript. Every PHP statement ends with a semicolon; Note

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

With the continuous development of the Internet, Web applications have become an important part of enterprise information construction and a necessary means of modernization work. In order to make web applications easy to develop, maintain and expand, developers need to choose a technical framework and programming language that suits their development needs. PHP and AngularJS are two very popular web development technologies. They are server-side and client-side solutions respectively. Their combined use can greatly improve the development efficiency and user experience of web applications. Advantages of PHPPHP

If you want to work in the IT industry, but do you want to learn programming, which technology should you choose? Of course it is Linux operation and maintenance. Linux is a very popular technology on the market, with a wide range of applications and good employment prospects, and is liked by many people. So the question is, can I learn Linux operation and maintenance with zero basic knowledge? In the server market, Linux system has a market share of up to 80% because of its advantages such as stability, security, free open source, efficiency and convenience. From this, it can be seen that Linux applications are very popular. Extensive. Whether now or in the future, learning Linux is a very good choice. As for whether it is possible to learn from scratch? My answer is of course. Oldboy Education Linux face-to-face class is specially designed for people with zero basic knowledge

Go language is a statically typed, compiled language developed by Google. Its concise and efficient features have attracted widespread attention and love from developers. In the process of learning the Go language, mastering the basic knowledge of variables is a crucial step. This article will explain basic knowledge such as the definition, assignment, and type inference of variables in the Go language through specific code examples to help readers better understand and master these knowledge points. In the Go language, you can use the keyword var to define a variable, which is the format of the var variable name variable type.

Basic introduction to PHP: How to use the echo function to output text content. In PHP programming, you often need to output some text content to a web page. In this case, you can use the echo function. This article will introduce how to use the echo function to output text content and provide some sample code. Before starting, first make sure you have installed PHP and configured the running environment. If PHP is not installed yet, you can download the latest stable version from the PHP official website (https://www.php.net).

With the rapid development of Web technology, Single Page Web Application (SinglePage Application, SPA) has become an increasingly popular Web application model. Compared with traditional multi-page web applications, the biggest advantage of SPA is that the user experience is smoother, and the computing pressure on the server is also greatly reduced. In this article, we will introduce how to build a simple SPA using Flask and AngularJS. Flask is a lightweight Py
