Angular.js Study 1

Source: Internet
Author: User

Before very early heard of NG, but has not been contacted to study, at that time feel not to do a backstage do not learn h5 not learn JS frame, until a period of time based on tp3.2, oneself can complete the simple PC station backstage, only began to H5 and NG study.

It's still exciting to see Ng's documentation because:

The red circle is available on tp or vue(which has been self-taught on the basis of official documents), as is the case with dependency injection, which seems to be tp5. I think it's not too difficult to get started.

The Angularjs is written as ng for simple unification.

Here we go,angular:

1: First of all, what is an instruction?

  Directives can be interpreted as declaring special labels or attributes

Ng has a lot of instructions, all the tags you see that start with Ng, like Ng-app, Ng-init, Ng-if, Ng-model, and so on, which are very similar to Vue, V-model,v-on,v-if and so on.

Ng-app: Used to identify the page is a Angularjs page. General loading HTML on the root object

Ng-init: Used to initialize a variable

Ng-model: We can bind the input box with Ng-model so that we can use the dynamic fetch value of the data object. You can think of Ng-model as a property of a specified property, just like an HTML element. Two-way data binding here can be used on many form elements,

such as input, textarea, select. NG uses the Ng-model directive to bind a single data that we want to be able to update with user input operations.

  

2: First NG demo initial knowledge Command:

<! DOCTYPE html>"en">"  UTF-8">    <title>Title</title>     <input type="text" ng-model="name" >{{name}}</div><script src="angular.min.js"> </script></body>

Performance as:

NG binds data to an HTML tag in the form of an expression. Ng's expression is written in two curly braces: {{name}}, and theNg-model instruction implements two-way data binding . When we change the value of the input box , the corresponding change is reflected in the {{name}} expression .

2: Second NG demo initial template:

1: Take TP For example, all page rendering is done on the service side. Template layout, template inheritance, variable output, etc., which inevitably aggravate the pressure on the server side,

The 2:ng has a built-in front-end template engine that renders all page renders on the browser side.

3: The template in ng refers to the HTML code with the NG-APP directive. Ng discovers whether the HTML page needs to be rendered with the NG template engine is the Ng-app tag

4: In Ng, what we write is not a pure HTML page, but a template, and the end user sees an HTML page (that is, a view) that is rendered by the template.

See Code:

<! DOCTYPE html>

Performance as:

At this point you may feel that this is not the same as the data binding above? Why write more of the extra code?

Let's start by exploring the difference from the first demo.

(1): ng-app= "CAPP"

(2): ng-controller= "Tempcontroller"

(3):

<script>(function () {//Create a module            varMainapp = Angular.module ("cApp",[]); //create a controller and inject scopeMainapp.controller ("Tempcontroller", ["$scope", Function ($scope) {$scope. val="Hello World";        }]); })()    </script>

Will find out more of these three different, when the three of any one removed when the two-way binding will not take effect.

At this point, you can understand the operation output for one of the specified modules.

(Not to be continued:

Angular.js Study 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.