webx exp 8
webx exp 8
D.O.P. 20/03/2025
D.O.S. 27/03/2025
Problem Statement:
a) Demonstrate with an AngularJS code one way data binding and two way data
binding in AngularJS
c) Users want to search for books by title, author, or genre. To accomplish this,
develop an AngularJS custom filter named bookFilter and include it into the
application.
d) Create a reusable and modular custom AngularJS service to handle user
authentication. Include this service into an application.
Theory:-
Directives in AngularJS
Directives are one of the core features of AngularJS that allow developers to extend
HTML functionality. They are special markers on DOM elements (such as attributes,
elements, or CSS classes) that tell AngularJS to attach specific behaviors to those
elements or transform them.
Commonly Used Directives in AngularJS:
3. ng-bind: Replaces the content of an HTML element with the value of an
expression.
Data binding is the process of synchronizing data between the model and the view.
AngularJS supports two types of data binding:
One-way Data Binding: The model updates the view, but changes in the view do not
affect the model. Example:
html
CopyEdit
<span ng-bind="message"></span>
1.
Two-way Data Binding: The model and view are linked such that changes in one
reflect in the other. Example:
html
CopyEdit
<input type="text" ng-model="username">
<p>Hello, {{username}}!</p>
2.
Two-way data binding is one of AngularJS's most powerful features, reducing the need
for manual DOM manipulation.
Form validation in AngularJS ensures that user input is correct before submission.
AngularJS provides built-in directives for form validation:
2. ng-minlength / ng-maxlength: Sets minimum and maximum character limits for
input fields.
Example:
html
CopyEdit
<form name="userForm">
<input type="email" name="email" ng-model="userEmail"
ng-required="true">
<span ng-show="userForm.email.$error.required">Email is
required.</span>
</form>
AngularJS tracks form states such as $pristine, $dirty, $valid, and $invalid
to provide real-time validation feedback.
1. Define scope variables: Controllers bind data to the view using the $scope
object.
2. Handle business logic: Controllers process user input and manipulate the
model accordingly.
3. Communicate with services: They fetch data from APIs or services.
Example:
javascript
CopyEdit
app.controller('MainController', function($scope) {
$scope.message = "Welcome to AngularJS!";
});
In the view:
html
CopyEdit
<div ng-controller="MainController">
<p>{{ message }}</p>
</div>
Example:
html
CopyEdit
<p>{{ "hello world" | uppercase }}</p>
<p>{{ 1000 | currency }}</p>
<p>{{ myDate | date:'short' }}</p>
bookfilter.js
Style.css
OUTPUT:-