« Previous | 1 | 2 | 3 | Next »
Include AngularJS: We have included the AngularJS JavaScript file in the HTML page so we can use AngularJS −
<script src = ttp://javatechnologycenter.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
Point to AngularJS app
Next we tell what part of the HTML contains the AngularJS app. This done by adding the ng-app attribute to the root HTML element of the AngularJS app. You can either add it to html element or body element as shown below −
<body ng-app = "myapp">
View The view is this part −
<div ng-controller = "HelloController" >
<h2>Welcome {{helloTo.title}}</h2>
ng-controller tells AngularJS what controller to use with this view. helloTo.title tells AngularJS to write the "model" value named helloTo.title to the HTML at this location.
Controller The controller part is −
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
This code registers a controller function named HelloController in the angular module named myapp. We will study more about modules and controllers in their respective chapters. The controller function is registered in angular via the angular.module(...).controller(...) function call.
The $scope parameter passed to the controller function is the model. The controller function adds a helloTo JavaScript object, and in that object it adds a title field.
« Previous | 1 | 2 | 3 | Next »

copyright © 2014 - all rights riserved by javatechnologycenter.com