Reproduced Angularjs Getting Started Tutorial 00: Boot Program

Source: Internet
Author: User

We are now ready to write the ANGULARJS application--phonecat. This step (step 0), you will be familiar with the important source code files, learn to launch the development environment containing the ANGULARJS seed project, and run the app on the browser side.

    1. Enter the Angular-phonecat directory and run the following command:

      Git checkout-f step-0

      This command resets the working directory of the Phonecat project, and it is recommended that you run this command at each learning step to change the number in the command to the number that corresponds to your learning step, which clears any changes you make in the working directory.

    2. Run the following command:

      Node Scripts/web-server.js

      To start the server, the command line terminal will be prompted Http Server running at http://localhost:8000 after startup, please do not close the terminal, shut down the terminal is shut down the server.

    3. Enter http://localhost:8000/app/index.html in the browser to access our Phonecat app.

Now, in the browser you should have seen our initial application, very simple, but it shows that our project is ready to run.

"Nothing here yet!" shown in the app is built from the following HTML code, which contains the key elements of Angularjs, which is what we need to learn.

App/index.html

<!DOCTYPE HTML><HTMLLang= "en"Ng-app><Head>    <MetaCharSet= "Utf-8">    <title>My HTML File</title>    <Linkrel= "stylesheet"href= "Css/app.css">    <Linkrel= "stylesheet"href= "Css/bootstrap.css">    <Scriptsrc= "Lib/angular/angular.js"></Script></Head><Body><P>Nothing here {{' yet ' + '! '}}</P></Body></HTML>

What does the code do? ng-appInstructions:
<lang= "en"  ng-app>

ng-appThe directive marks the scope of the Angularjs script, and adding the attribute in it means that the ng-app entire angularjs script scope. Developers can also use directives locally ng-app , such as the <div ng-app> Angularjs script to run only in that <div> .

Angularjs Script Tags:
<src= "Lib/angular/angular.js"></script  >

This line of code loads the Angular.js script, and when the browser loads the entire HTML page, the Angular.js script will be executed, and the Angular.js script will look for ng-app HTML tags that contain instructions after it is run. The tag defines the scope of the Angularjs app.

Expression for double curly braces binding:
< P > Nothing here {{' yet ' + '! '}} </ P >

This line of code demonstrates the core functionality of the Angularjs template-binding, which consists of double curly braces {{}} and expressions ‘yet‘ + ‘!‘ .

This binding tells Angularjs to need to operate the expression and insert the result into the DOM, and the next step we'll see is that the DOM can be updated in real time as the result of the expression operation changes.

Angularjs expressions angular expression is a JavaScript-like code fragment that Angularjs expressions run only in the scope of ANGULARJS, not throughout the DOM.

Guided ANGULARJS applications

Using the Ngapp directive to automatically guide the ANGULARJS application is a neat way to fit most situations. In advanced development, such as using a script to load an app, you can also use bootstrap to manually boot the Angularjs app.

The ANGULARJS application boot process has 3 important points:

    1. The injector (injector) will be used to create a dependency injection (dependency injection) for this application;
    2. The injector will create the root scope as the scope of our application model;
    3. Angularjs will link the DOM in the root scope, starting with the HTML tag tagged with Ngapp, and gradually processing the instructions and bindings in the DOM.

Once the Angularjs app is booted, it will continue to listen for browser HTML-triggered events, such as mouse click events, keystroke events, HTTP incoming responses, and other changes to the DOM model. Once such incidents occur, ANGULARJS will automatically detect changes and make corresponding processing and updates.

The structure of the application above is very simple. The template package contains only one instruction and one static binding, and the model is empty. Next we try a slightly more complex application!

What are the files in my working directory?

The above app comes from the Angularjs seed project, and we can usually use the Angularjs seed project to create a new project. The seed project includes the latest ANGULARJS code base, test libraries, scripts, and a simple application sample that contains the basic configuration needed to develop a typical Web application.

For this tutorial, we made the following changes to the Angularjs seed project:

    1. Remove the sample application;
    2. Add phone images to app/img/phones/;
    3. Add mobile data Files (JSON) to app/phones/;
    4. Add Twitter bootstrap files to app/css/and app/img/.
Practice

Try adding new expressions about mathematical operations to index.html:

< P >1 + 2 = {{1 + 2}}</p>
Summarize

Now let's go to step 1 and add some content to the Web application.

Original: http://www.angularjs.cn/A003

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.