AngularJS > Overview

How to setup AngularJS? in AngularJS

How to setup AngularJS in the web page?


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.

  • The <html> tag has 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.
     
  • The <script> tag simply refers the AngularJS library from Google CDN
     
  • The {{ 2 + 1 }} is an expression that is validated by AngularJS. This is the example of one way binding and it is done by wrapping the code in {{ and }} characters. If the expression contains variables, it keeps the User interface up to date when the variable value changes.

In next post, we shall learn how to load AngularJS files from CDN.

 Views: 18545 | Post Order: 3




Write for us






Hosting Recommendations