To setup AngularJS in the web page, first we need to refer the AngularJS library. To do this, go to the official website of AngularJS and download the .js file - https://angularjs.org/.
Now add the reference of AngularJS library in the web page.
<!DOCTYPE html> <html ng-app> <head> <title>AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> Hello world. <p>The sum of 2 and 1 is equal to <b>{{ 2 + 1 }}</b></p> </body> </html>
Notice the highlighted code in the above code snippet.
ng-app
attribute that is used to bootstrap the AngularJS, this is the first and most important directive that denotes that AngularJS is going to controll this and all its children elements. This attribute can be applied to <html>, <body>, </div> or any other valid HTML element. It always good to add this attribute to the <html> or <body> element so that entire web page elements will be avialable to AngularJS to control.In next post, we shall learn how to load AngularJS files from CDN.
Views: 18501 | Post Order: 3