SlideShare a Scribd company logo
1 of 37
Download to read offline
www.webstackacademy.com
Data and Event Handling
Angular
www.webstackacademy.comwww.webstackacademy.com
Interpolation
(Connecting data with view)
www.webstackacademy.com
Interpolation
• At high level component can be broken into two parts:
 View - Which takes care of the look & Feel (HTML + CSS)
 Business logic - Which takes care of the user and server interactivity (TypeScript -> JavaScript)
{ } <#>
courses.component.ts
courses.services.ts
courses.component.html
courses.component.css
Data
How to access data from into template?
www.webstackacademy.com
Interpolation
• The major difference between writing them in a 'vanilla' fashion (how we have done during
JavaScript module) and Angular is we have followed certain rules
• The main goal of these rules is to de-couple the View (HTML + CSS) and Business Logic
• This makes components re-usable, modular and maintainable which is required for SPA
• In real-world applications these two need to work together by communicating properties
(variables, objects, arrays, etc..) from the component class to the template, you can use
interpolation
• This is achieved with the notation {{ propertyName }} in the template. With this
approach whenever we are changing the functionality, the template don’t need to change.
• This way of connection is called as Binding
www.webstackacademy.com
Interpolation
@Component({
selector: 'courses',
template: `
<h2> {{title}}</h2>
<ul> {{courses}}</ul>
`
})
export class CoursesComponent {
title = 'List of courses in WSA:';
courses = ["FullStack","FrontEnd","BackEnd"]
}
{}
<#>
www.webstackacademy.comwww.webstackacademy.com
Binding
(Connecting data with view)
www.webstackacademy.com
Binding – Big picture
www.webstackacademy.com
DOM - Revisiting
 The Document Object Model (DOM) is a cross-platform and language-independent
application programming interface
 The DOM, is the API through which JavaScript interacts with content within a website
 The DOM API is used to access, traverse and manipulate HTML and XML documents
 The HTML is represented in a tree format with each node representing a property
 Nodes have “parent-child” relationship tracing back to the “root” <html>
www.webstackacademy.com
DOM - Revisiting
www.webstackacademy.com
DOM and HTML
<html>
<body>
<h1> Courses in WSA </h1>
<ul>
<li> FullStack web developer</li>
<li> Frontend web developer </li>
<li> Backend web developer </li>
<ul>
</body>
</html>
www.webstackacademy.com
DOM and HTML – Zooming In!
www.webstackacademy.com
Attribute Binding (One way: Business logic -> View)
export class BindingComponent {
imageLink = "http://www.testimage.com/side-image.png";
}
<p><b>Example of property binding: Image</b></p>
<img [src]= "imageLink"/>
{}
<#>
www.webstackacademy.com
HTML - DOM element object
Following are some of the properties that can be used on all HTML elements
Property Description
clientHeight Returns the height of an element, including padding
Id Sets or returns the value of the id attribute of an element
innerHTML Sets or returns the content of an element
Style Sets or returns the value of the style attribute of an element
textContent Sets or returns the textual content of a node and its descendants
Title Sets or returns the value of the title attribute of an element
nextSibling Returns the next node at the same node tree level
nodeType Returns the node type of a node
www.webstackacademy.comwww.webstackacademy.com
Event Binding
(Capturing events from the view)
www.webstackacademy.com
Event Binding
• In property binding, typically the changes done in the business logic (functionality part) is
getting accessed from the view. It was achieved by the []notation, in combination with the
template (HTML) elements
• Event binding is the opposite of property binding where events from the template is sent back
to the business logic in form of event notification functions.
• Similar to how it was done with vanilla JavaScript, each event to have a call-back function along
with the event in order to notify in case of events
• User actions such as clicking a link, pushing a button, and entering text raise DOM events.
• This event binding is achieved with the ()notation
www.webstackacademy.com
Attribute Binding (One way: Business logic -> View)
{}
<#><button (click)="mySaveFunction()">Save</button>
export class EbindingComponent {
mySaveFunction() {
console.log ("Button was pressed”);
}
}
www.webstackacademy.com
More Event Handling…
<input (keyup.enter)="myKeyPress()">
Event Filtering: Event handlers can be called on a filtering basis.
View variables: Variables can be defined in the view in order to send value to business logic. These
variables are also called as Template Variables.
<input #userInput
(keyup.enter)="myKeyPressWithValue(userInput.value)">
www.webstackacademy.com
Event Binding
Methods Description
Click The event occurs when the user clicks on an element
Dbclick The event occurs when the user double-clicks on an element
Keyup The event occurs when the user releases a key
Mouseover The event occurs when the pointer is moved onto an element, or onto one of its children
Submit The event occurs when a form is submitted
Following are some of the important events which is used in event binding use-cases
www.webstackacademy.comwww.webstackacademy.com
Two way Binding
(Binding Business logic & View in both direction)
www.webstackacademy.com
Two way Binding
• One way binding in Angular is achieved in the following ways:
 From View to Business Logic (Event binding) : ()notation
 From Business logic to view (Data binding) : []notation
• They are also used in a combined manner. An event from the view
triggers a change in a HTML attribute (View->Business Logic->View)
[Ex: Changing another paragraph’s background with a button click
event]
• However handling two way binding is still not feasible with such
approaches.
• There are some ways we have achieved (ex: $event), but parameter
passing quite complex
• In order to achieve two way binding ngModel directive is used
www.webstackacademy.com
What is ngModel directive?
• ngModel is one of the directives supported by Angular to achieve two-way binding
• A directive is a custom HTML element (provided by Angular) that is used to extend the
power of HTML (More on this during next chapter)
• To set up two-way data binding with ngModel, you need to add an input in the template
and achieve binding them using combination of both square bracket and parenthesis
• With this binding whatever changes you are making in both view and business-logic get
synchronized automatically without any explicit parameter passing
<input [(ngModel)]="userInput" (keyup.enter)="userKeyPress()"/>
www.webstackacademy.com
How to use ngModel?
• ngModel is part of the Forms Module in Angular. It is not imported by default, hence it need to be done
explicitly by adding it into the app.module.ts file
www.webstackacademy.comwww.webstackacademy.com
Pipes
(Displaying data in a better way)
www.webstackacademy.com
Pipes
• Pipe takes input in the view and transforms into a better readable / understandable format
• Some of the standard pipes are supported, users can create their own pipes (custom pipes)
• Multiple pipes can be combined together to achieve the desired functionality
• Pipes are used along with text, from the template along with interpolation
• Pipes make application level handling of text much easier. Multiple pipes can also be combined
together
• In case of multiple pipes, output of one pipe is given as input of another
Pipe usage: {{ userText | Pipe }}
www.webstackacademy.com
Standard Pipes
Methods Description
Currency Formats the current input in form of currency (ex: currency:’INR’)
Date Transforms dates (shortDate | shortTime | fullDate)
Decimal Formats decimal numbers (number: ‘2.2-4’)
Lowercase Converts input into lower-case
Uppercase Converts input into upper case
Percent Convers into percentage format (percent:’2.2-5’)
www.webstackacademy.com
Exercise
• Using data binding, change the following HTML attributes by changing appropriate DOM
element:
• Font size
• Left Margin
• Top Margin
• Using event binding, handle the following events by having event handlers
• Mouse over
• Double click
• Change a HTML attribute of a text (ex: BackgroundColor) when the user click any of the
mouse events. Demonstrate view->business logic -> view binding
• Handle the following standard pipes
• Percentage
• Currency
www.webstackacademy.comwww.webstackacademy.com
Creating a Custom Pipe - GUI
(Implementing your own pipe functionality)
www.webstackacademy.com
Creating a pipe – GUI mode
 Step-1: Creating / Adding your pipe TS file
• Open your Angular project folder (ex: myFirstApp) in your editor (ex: VS code). Go to src/app folder.
• Add a new file in the following format: <pipe_name>.pipe.ts (ex: summarypipe.pipe.ts)
• Add the following lines into your new pipe file. Details given as comments.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ // Pipe decorator to tell Angular that we are implementing a pipe
name: 'summarypipe' // Pipe name, which need to be used in interpolation
})
export class SummarypipePipe implements PipeTransform {
transform(value: any,…, args?: any[]): any {
// Implement your pipe functionality here
}
www.webstackacademy.com
Implements interface
 Implements interface ensures classes must follow a particular structure that is already defined
 Basically ensures the class is of same ‘shape’
interface Point {
xValue : number;
yValue : number;
}
class MyPoint implements Point {
xValue: number;
yValue: number;
}
class MyPoint implements Point {
xValue: number;
yValue: number;
zValue: number;
}
www.webstackacademy.com
PipeTransform Interface
 The PipeTransform interface is defined in Angular (ref – below)
 The transform method is where the custom pipe functionality is implemented, which guides the
compiler to have a look-up and execute in run-time
 It will accept any number of any type of arguments and return the transformed value which also can be
of any type
interface PipeTransform {
transform(value: any, ...args: any[]): any
}
Angular official documentation URL: https://angular.io/guide/pipes
www.webstackacademy.com
Creating a pipe – GUI mode
 Step-2: Make your pipe as a part of the module (app.module.ts file)
• Add your new pipe (ex: SummaryPipe) under the declarations sections of the module.
• Ensure you import appropriate pipe files, similar to components
@NgModule({
declarations: [
AppComponent,
SummaryPipe
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
www.webstackacademy.com
Creating a pipe – GUI mode
 Step-3: Invoking / Using the pipe
 Pipe need to be invoked by the component from its template file
<h2>Custom pipe - Example</h2>
{{ myText | summarypipe }}
 Step-4: Save all and compile. U should be able to use your custom pipe now
www.webstackacademy.comwww.webstackacademy.com
Creating a Custom pipe - CLI
(CLI mode for custom pipes)
www.webstackacademy.com
Creating a component – CLI mode
• Sometimes you might find it little hard to create a component using GUI. In case you miss out
any steps, the app will not work.
• Angular CLI offers much more reliable way to create a pipe (similar to component and services).
Try out the following command, which will not only generate a component but also make
appropriate entries
$ ng g p myformat // Creates a new pipe
www.webstackacademy.com
Creating a pipe – CLI mode
www.webstackacademy.com
Exercise
• Create a custom pipe to find out the zodiac sign of the user
• Input is given as an entry in CSV file format as follows:
• Here are the Zodiac signs for all the months:
Rajan,9845123450,rajan@gmail.com,22/05/1990,Bangalore
• Aries (March 21-April 19)
• Taurus (April 20-May 20)
• Gemini (May 21-June 20)
• Cancer (June 21-July 22)
• Leo (July 23-August 22)
• Virgo (August 23-September 22)
• Libra (September 23-October 22)
• Scorpio (October 23-November 21)
• Sagittarius (November 22-December 21)
• Capricorn (December 22-January 19)
• Aquarius (January 20 to February 18)
• Pisces (February 19 to March 20)
www.webstackacademy.com
WebStack Academy
#83, Farah Towers,
1st Floor, MG Road,
Bangalore – 560001
M: +91-809 555 7332
E: training@webstackacademy.com
WSA in Social Media:

More Related Content

What's hot

Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipesKnoldus Inc.
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data BindingDuy Khanh
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & AnswersRatnala Charan kumar
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of AngularKnoldus Inc.
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Edureka!
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http clientGaurav Madaan
 

What's hot (20)

Angular
AngularAngular
Angular
 
Angular
AngularAngular
Angular
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipes
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & Answers
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Jquery
JqueryJquery
Jquery
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Express js
Express jsExpress js
Express js
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
Angular
AngularAngular
Angular
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
 

Similar to Angular - Chapter 4 - Data and Event Handling

AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
Google Polymer Introduction
Google Polymer IntroductionGoogle Polymer Introduction
Google Polymer IntroductionDavid Price
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxmanju451965
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlIlia Idakiev
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Amazon Web Services
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training Patrick Schroeder
 
angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxshekharmpatil1309
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databindingBoulos Dib
 

Similar to Angular - Chapter 4 - Data and Event Handling (20)

AngularJS
AngularJSAngularJS
AngularJS
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Google Polymer Introduction
Google Polymer IntroductionGoogle Polymer Introduction
Google Polymer Introduction
 
MCA-202-W4-L1.pptx
MCA-202-W4-L1.pptxMCA-202-W4-L1.pptx
MCA-202-W4-L1.pptx
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Test
TestTest
Test
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
 
Adding a view
Adding a viewAdding a view
Adding a view
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
 
angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptx
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databinding
 

More from WebStackAcademy

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesWebStackAcademy
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebStackAcademy
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online PortfolioWebStackAcademy
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career RoadmapWebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationWebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationWebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging TechniquesWebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced FunctionsWebStackAcademy
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 

More from WebStackAcademy (20)

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Angular - Chapter 4 - Data and Event Handling

  • 3. www.webstackacademy.com Interpolation • At high level component can be broken into two parts:  View - Which takes care of the look & Feel (HTML + CSS)  Business logic - Which takes care of the user and server interactivity (TypeScript -> JavaScript) { } <#> courses.component.ts courses.services.ts courses.component.html courses.component.css Data How to access data from into template?
  • 4. www.webstackacademy.com Interpolation • The major difference between writing them in a 'vanilla' fashion (how we have done during JavaScript module) and Angular is we have followed certain rules • The main goal of these rules is to de-couple the View (HTML + CSS) and Business Logic • This makes components re-usable, modular and maintainable which is required for SPA • In real-world applications these two need to work together by communicating properties (variables, objects, arrays, etc..) from the component class to the template, you can use interpolation • This is achieved with the notation {{ propertyName }} in the template. With this approach whenever we are changing the functionality, the template don’t need to change. • This way of connection is called as Binding
  • 5. www.webstackacademy.com Interpolation @Component({ selector: 'courses', template: ` <h2> {{title}}</h2> <ul> {{courses}}</ul> ` }) export class CoursesComponent { title = 'List of courses in WSA:'; courses = ["FullStack","FrontEnd","BackEnd"] } {} <#>
  • 8. www.webstackacademy.com DOM - Revisiting  The Document Object Model (DOM) is a cross-platform and language-independent application programming interface  The DOM, is the API through which JavaScript interacts with content within a website  The DOM API is used to access, traverse and manipulate HTML and XML documents  The HTML is represented in a tree format with each node representing a property  Nodes have “parent-child” relationship tracing back to the “root” <html>
  • 10. www.webstackacademy.com DOM and HTML <html> <body> <h1> Courses in WSA </h1> <ul> <li> FullStack web developer</li> <li> Frontend web developer </li> <li> Backend web developer </li> <ul> </body> </html>
  • 12. www.webstackacademy.com Attribute Binding (One way: Business logic -> View) export class BindingComponent { imageLink = "http://www.testimage.com/side-image.png"; } <p><b>Example of property binding: Image</b></p> <img [src]= "imageLink"/> {} <#>
  • 13. www.webstackacademy.com HTML - DOM element object Following are some of the properties that can be used on all HTML elements Property Description clientHeight Returns the height of an element, including padding Id Sets or returns the value of the id attribute of an element innerHTML Sets or returns the content of an element Style Sets or returns the value of the style attribute of an element textContent Sets or returns the textual content of a node and its descendants Title Sets or returns the value of the title attribute of an element nextSibling Returns the next node at the same node tree level nodeType Returns the node type of a node
  • 15. www.webstackacademy.com Event Binding • In property binding, typically the changes done in the business logic (functionality part) is getting accessed from the view. It was achieved by the []notation, in combination with the template (HTML) elements • Event binding is the opposite of property binding where events from the template is sent back to the business logic in form of event notification functions. • Similar to how it was done with vanilla JavaScript, each event to have a call-back function along with the event in order to notify in case of events • User actions such as clicking a link, pushing a button, and entering text raise DOM events. • This event binding is achieved with the ()notation
  • 16. www.webstackacademy.com Attribute Binding (One way: Business logic -> View) {} <#><button (click)="mySaveFunction()">Save</button> export class EbindingComponent { mySaveFunction() { console.log ("Button was pressed”); } }
  • 17. www.webstackacademy.com More Event Handling… <input (keyup.enter)="myKeyPress()"> Event Filtering: Event handlers can be called on a filtering basis. View variables: Variables can be defined in the view in order to send value to business logic. These variables are also called as Template Variables. <input #userInput (keyup.enter)="myKeyPressWithValue(userInput.value)">
  • 18. www.webstackacademy.com Event Binding Methods Description Click The event occurs when the user clicks on an element Dbclick The event occurs when the user double-clicks on an element Keyup The event occurs when the user releases a key Mouseover The event occurs when the pointer is moved onto an element, or onto one of its children Submit The event occurs when a form is submitted Following are some of the important events which is used in event binding use-cases
  • 20. www.webstackacademy.com Two way Binding • One way binding in Angular is achieved in the following ways:  From View to Business Logic (Event binding) : ()notation  From Business logic to view (Data binding) : []notation • They are also used in a combined manner. An event from the view triggers a change in a HTML attribute (View->Business Logic->View) [Ex: Changing another paragraph’s background with a button click event] • However handling two way binding is still not feasible with such approaches. • There are some ways we have achieved (ex: $event), but parameter passing quite complex • In order to achieve two way binding ngModel directive is used
  • 21. www.webstackacademy.com What is ngModel directive? • ngModel is one of the directives supported by Angular to achieve two-way binding • A directive is a custom HTML element (provided by Angular) that is used to extend the power of HTML (More on this during next chapter) • To set up two-way data binding with ngModel, you need to add an input in the template and achieve binding them using combination of both square bracket and parenthesis • With this binding whatever changes you are making in both view and business-logic get synchronized automatically without any explicit parameter passing <input [(ngModel)]="userInput" (keyup.enter)="userKeyPress()"/>
  • 22. www.webstackacademy.com How to use ngModel? • ngModel is part of the Forms Module in Angular. It is not imported by default, hence it need to be done explicitly by adding it into the app.module.ts file
  • 24. www.webstackacademy.com Pipes • Pipe takes input in the view and transforms into a better readable / understandable format • Some of the standard pipes are supported, users can create their own pipes (custom pipes) • Multiple pipes can be combined together to achieve the desired functionality • Pipes are used along with text, from the template along with interpolation • Pipes make application level handling of text much easier. Multiple pipes can also be combined together • In case of multiple pipes, output of one pipe is given as input of another Pipe usage: {{ userText | Pipe }}
  • 25. www.webstackacademy.com Standard Pipes Methods Description Currency Formats the current input in form of currency (ex: currency:’INR’) Date Transforms dates (shortDate | shortTime | fullDate) Decimal Formats decimal numbers (number: ‘2.2-4’) Lowercase Converts input into lower-case Uppercase Converts input into upper case Percent Convers into percentage format (percent:’2.2-5’)
  • 26. www.webstackacademy.com Exercise • Using data binding, change the following HTML attributes by changing appropriate DOM element: • Font size • Left Margin • Top Margin • Using event binding, handle the following events by having event handlers • Mouse over • Double click • Change a HTML attribute of a text (ex: BackgroundColor) when the user click any of the mouse events. Demonstrate view->business logic -> view binding • Handle the following standard pipes • Percentage • Currency
  • 27. www.webstackacademy.comwww.webstackacademy.com Creating a Custom Pipe - GUI (Implementing your own pipe functionality)
  • 28. www.webstackacademy.com Creating a pipe – GUI mode  Step-1: Creating / Adding your pipe TS file • Open your Angular project folder (ex: myFirstApp) in your editor (ex: VS code). Go to src/app folder. • Add a new file in the following format: <pipe_name>.pipe.ts (ex: summarypipe.pipe.ts) • Add the following lines into your new pipe file. Details given as comments. import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ // Pipe decorator to tell Angular that we are implementing a pipe name: 'summarypipe' // Pipe name, which need to be used in interpolation }) export class SummarypipePipe implements PipeTransform { transform(value: any,…, args?: any[]): any { // Implement your pipe functionality here }
  • 29. www.webstackacademy.com Implements interface  Implements interface ensures classes must follow a particular structure that is already defined  Basically ensures the class is of same ‘shape’ interface Point { xValue : number; yValue : number; } class MyPoint implements Point { xValue: number; yValue: number; } class MyPoint implements Point { xValue: number; yValue: number; zValue: number; }
  • 30. www.webstackacademy.com PipeTransform Interface  The PipeTransform interface is defined in Angular (ref – below)  The transform method is where the custom pipe functionality is implemented, which guides the compiler to have a look-up and execute in run-time  It will accept any number of any type of arguments and return the transformed value which also can be of any type interface PipeTransform { transform(value: any, ...args: any[]): any } Angular official documentation URL: https://angular.io/guide/pipes
  • 31. www.webstackacademy.com Creating a pipe – GUI mode  Step-2: Make your pipe as a part of the module (app.module.ts file) • Add your new pipe (ex: SummaryPipe) under the declarations sections of the module. • Ensure you import appropriate pipe files, similar to components @NgModule({ declarations: [ AppComponent, SummaryPipe ], imports: [ BrowserModule, ], providers: [], bootstrap: [AppComponent] })
  • 32. www.webstackacademy.com Creating a pipe – GUI mode  Step-3: Invoking / Using the pipe  Pipe need to be invoked by the component from its template file <h2>Custom pipe - Example</h2> {{ myText | summarypipe }}  Step-4: Save all and compile. U should be able to use your custom pipe now
  • 34. www.webstackacademy.com Creating a component – CLI mode • Sometimes you might find it little hard to create a component using GUI. In case you miss out any steps, the app will not work. • Angular CLI offers much more reliable way to create a pipe (similar to component and services). Try out the following command, which will not only generate a component but also make appropriate entries $ ng g p myformat // Creates a new pipe
  • 36. www.webstackacademy.com Exercise • Create a custom pipe to find out the zodiac sign of the user • Input is given as an entry in CSV file format as follows: • Here are the Zodiac signs for all the months: Rajan,9845123450,rajan@gmail.com,22/05/1990,Bangalore • Aries (March 21-April 19) • Taurus (April 20-May 20) • Gemini (May 21-June 20) • Cancer (June 21-July 22) • Leo (July 23-August 22) • Virgo (August 23-September 22) • Libra (September 23-October 22) • Scorpio (October 23-November 21) • Sagittarius (November 22-December 21) • Capricorn (December 22-January 19) • Aquarius (January 20 to February 18) • Pisces (February 19 to March 20)
  • 37. www.webstackacademy.com WebStack Academy #83, Farah Towers, 1st Floor, MG Road, Bangalore – 560001 M: +91-809 555 7332 E: training@webstackacademy.com WSA in Social Media: