Angular JS
Angular JS
Introduction
Angular JS
It is maintained by Google.
<html>
<head>
<title>AngularJS First Application</title> </head> <body>
<h1>Sample Application</h1>
<div ng-app = "">
<p>Enter your Name:
<input type = "text" ng-model = "name"></p>
<p>Hello <span ng-bind = "name"></span>!</p> </div>
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/ang
ular.min.js">
</script> </body> </html>
Core Features
Controller
<script> angular.module("myapp",
[]) .controller("HelloController", function($scope)
{ $scope.helloTo = {}; $scope.helloTo.title =
“krish”; }); </script>
AngularJS first example
What happens when the page is loaded in the browser ?
Using Strings
<p>Hello {{student.firstname + " " + student.lastname}}!</p>
Using Object
<p>Roll No: {{student.rollno}}</p>
Expressions
Using Array
<p>Marks(Math): {{marks[3]}}</p>
Tables
Table data is generally repeatable. The ng-repeat directive can
be used to draw table easily. The following example shows the
use of ng-repeat directive to draw a table −
<table>
<tr> <th>Name</th> <th>Marks</th> </tr>
<tr ng-repeat = "subject in student.subjects">
<td>{{ subject.name }}</td>
<td>{{ subject.marks }}</td> </tr>
</table>
Tables
Table can be styled using CSS Styling.
<style> table, th , td { border: 1px solid grey; border-collapse:
collapse; padding: 5px; }
Similarly, for numbers, you can use other filters. During this
tutorial, we will see the different standard built-in filters
available in Angular.
Custom Filters in AngularJS
Directives in AngularJS
A Directive in AngularJS is a command that gives HTML new
functionality.
The directives are used to bind our data model to our view.
Directives in AngularJS
1. ng-app
2. ng-init
3. ng-model
4. ng-repeat
ng-model:
The ng-model directive is used to bind the value of HTML
control to application data.
ng-repeat
This is used to repeat an HTML element.
Directives (ng-app)
Directives (ng-init)
Directives (ng-model)
Directives (ng-repeat)
Event Handling in AngularJs
AngularJS events are the functionalities that allow web
applications to interact with user inputs like mouse click,
keyboard inputs, mouse hover etc.
ng-click
ng-hide
ng-show