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

Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular ComponentsSquash Apps Pvt Ltd
 
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 components
Angular componentsAngular components
Angular componentsSultan Ahmed
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Visual Engineering
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...Katy Slemon
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data BindingDuy Khanh
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSDavid Parsons
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training sessionHrichi Mohamed
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 

What's hot (20)

Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
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 Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular components
Angular componentsAngular components
Angular components
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
NestJS
NestJSNestJS
NestJS
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Angular
AngularAngular
Angular
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 

Similar to Angular Data Binding, Pipes 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 Data Binding, Pipes 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
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
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 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
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
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 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

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Angular Data Binding, Pipes 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: