Introduction
Here iam trying to explain what is the use of ng-app( one of the AngularJS directive ).
In AngularJS every application must be intialized with the binding of ng-app directive. ng-app is adding as an attribute to the DOM of HTML page. Generaly ng-app will be adding to html tag or body tag, to let that DOM is binding to AngularJS module.
ng-app is a root for AngularJS application. With ng-app we can initialize AngularJS to HTMl page/application
<html> <head> </head> <body ng-app="cookiestore_app"> <div ng-controller="welcomeBlock"> {{message}} </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script> <script src="./app/app.js"></script> </body> </html>
In the above code in line 6 we have added an attribute ng-app to body tab with the value as cookiestore_app, that means AngulaJS intiated here.
We bind AngularJS controller to the DOM div where controller named as welcomeBlack assighned as a value to one more AngularJS directive ng-controller
var appRoot=angular.module("cookiestore_app",[]); (function() { 'use strict'; appRoot.controller('welcomeBlock', welcomeBlock); welcomeBlock.$inject = ['$scope']; function welcomeBlock($scope) { var vm = this; $scope.message="Welcome to my site"; activate(); //////////////// function activate() { } } })();
In line 1 from the above code ( app.js ) we have initiated cookiestore_app as an AngularJS module, by passing ng-app value as a first parameter to function angular.module() and dependencies can be added in array, but here in this example no dependecies are passing so that we are passing empty array as a second parameter.
Output |
Post a Comment
Post a Comment