How to write Hello World by using JavaScript's ANGULARJS library

Source: Internet
Author: User


This article shows the Hello World code example implemented by the ANGULARJS framework.



Here are some things you need to focus on when you look at the Hello World example and the next code example.


    • Ng-app, Ng-controller, Ng-model command.
    • A template with two braces


Step 1: Include angular Javascript in the <Head> section



Include the following code in

<script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js" ></script>


Step 2: Apply the NG-APP directive to the <Html> element



The following applies the NG-APP directive to the

<html ng-app="helloApp">


Step 3: Apply the Ng-controller directive to the <Body> element



Apply the Ng-controller directive to the <Body> element. Controller directives can be applied to any element, such as Div. In the following code, "Helloctrl" is the name of the controller and can be placed in the Controller code reference at the



<body ng-controller= "Helloctrl" >


Step 4: Apply the Ng-model directive to the INPUT element



You can use the Ng-model directive to bind input with the model.



<input type= "text" name= "name" ng-model= "name"/>


Step 5: Write the template code



The following is the template code that shows the model value of the model with the name "name". Note that the model named "name" is bound to the input in step four.



Hello {{name}}! How are your doing today?



Step 6: Create the controller code in <Script>



Create the controller code in the script element as follows. In the following code, "HelloApp" is the name of the module that is defined in the

<script>     var helloApp = angular.module("helloApp", []);
    helloApp.controller("HelloCtrl", function($scope) {
    $scope.name = "Calvin Hobbes";
    }); </script>



Related Article

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.