Angular JS
What is Angular JS?
- Angular Js is a JavaScript framework that helps to build web applications. It lets you use HTML as your template language and lets extends HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
Benefits of Angular JS
- Dependency injection
- Two way data-binding
- Testing
- Model View Controller (MVC)
- Directives
- Filters
Getting started with Angular
- First need to get the angular js file from https://angularjs.org/ web site. Instead of downloading the JavaScript file you can also use a CDN to add Angular js files.
First we will create a simple application using Angular JS
<!DOCTYPE html>
<html>
<head>
<script src="angular-1.6.4/angular.js"></script>
<script src="angular-1.6.4/angular.min.js"></script>
</head>
<body ng-app>
<div>
10+20 = {{10+20}}
</div>
</body>
</html>
Output : 10+20 = 30
Angular modules and controllers
What is a module?
- A module is a container for different parts of your application
How to create a module?
- Use the angular object's module() method to create a module
What is a controller?
- In angular a controller is a JavaScript function. The job of the controller is to build a model for the view to display
create a script.js file & include the following code
var myapp = anjular.module("myModule",[]);
myapp.controller("myController",function($scope)){
$scope.message="Angular Tutorial";
}
Modify the html code to
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="angular-1.6.4/angular.js"></script>
<script src="angular-1.6.4/angular.min.js"></script>
<script src="Script.js"></script>
</head>
<body>
<div ng-controller="myController">
{{message}}
</div>
</body>
</html>
Output : Angular Tutorial


No comments:
Post a Comment