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>