SlideShare a Scribd company logo
1 of 14
Download to read offline
Angular 4
i
Angular 4
i
AbouttheTutorial
Angular 4 is a JavaScript framework for building web applications and apps in JavaScript,
html, and TypeScript, which is a superset of JavaScript. Angular provides built-in features
for animation, http service, and materials which in turn has features such as auto-
complete, navigation, toolbar, menus, etc. The code is written in TypeScript, which
compiles to JavaScript and displays the same in the browser.
Audience
This tutorial is designed for software programmers who want to learn the basics of Angular
4 and its programming concepts in a simple and easy manner. This tutorial will give you
enough understanding on the various functionalities of Angular 4 with suitable examples.
Prerequisites
Before proceeding with this tutorial, you should have a basic understanding of HTML, CSS,
JavaScript, TypeScript, and Document Object Model (DOM).
Copyright&Disclaimer
 Copyright 2017 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com
Angular 4
ii
TableofContents
About the Tutorial ............................................................................................................................................i
Audience...........................................................................................................................................................i
Prerequisites.....................................................................................................................................................i
Copyright & Disclaimer.....................................................................................................................................i
Table of Contents ............................................................................................................................................ ii
1. Angular 4 – Overview................................................................................................................................1
Why Angular4 and Not Angular3?...................................................................................................................1
2. Angular 4 – Environment Setup ................................................................................................................3
3. Angular 4 – Project Setup..........................................................................................................................6
4. Angular 4 – Components.........................................................................................................................26
5. Angular 4 – Module.................................................................................................................................35
6. Angular 4 – Data Binding.........................................................................................................................38
7. Angular 4 – Event Binding .......................................................................................................................45
8. Angular 4 – Templates ............................................................................................................................51
9. Angular 4 – Directives .............................................................................................................................55
How to Create Custom Directives?................................................................................................................55
10. Angular 4 – Pipes ....................................................................................................................................59
How to Create a Custom Pipe?......................................................................................................................64
11. Angular 4 – Routing ................................................................................................................................67
12. Angular 4 – Services................................................................................................................................72
13. Angular 4 – Http Service..........................................................................................................................81
14. Angular 4 – Forms...................................................................................................................................88
Template Driven Form...................................................................................................................................88
Model Driven Form........................................................................................................................................91
Form Validation .............................................................................................................................................94
15. Angular 4 – Animations...........................................................................................................................99
Angular 4
iii
16. Angular 4 – Materials............................................................................................................................105
17. Angular 4 – CLI ......................................................................................................................................114
18. Angular 4 – Examples............................................................................................................................115
Angular 4
4
There are three major releases of Angular. The first version that was released is Angular1,
which is also called AngularJS. Angular1 was followed by Angular2, which came in with a lot
of changes when compared to Angular1.
The structure of Angular is based on the components/services architecture. AngularJS was
based on the model view controller. Angular 4 released in March 2017 proves to be a major
breakthrough and is the latest release from the Angular team after Angular2.
Angular 4 is almost the same as Angular 2. It has a backward compatibility with Angular 2.
Projects developed in Angular 2 will work without any issues with Angular 4.
Let us now see the new features and the changes made in Angular 4.
WhyAngular4andNotAngular3?
The Angular team faced some versioning issues internally with their modules and due to the
conflict they had to move on and release the next version of Angular – the Angular4.
Let us now see the new features added to Angular 4:
ngIf
Angular2 supported only the if condition. However, Angular 4 supports the if else condition
as well. Let us see how it works using the ng-template.
<span *ngIf="isavailable; else condition1">Condition is valid.</span>
<ng-template #condition1>Condition is invalid</ng-template>
as keyword in for loop
With the help of as keyword you can store the value as shown below:
<div *ngFor="let i of months | slice:0:5 as total">
Months: {{i}} Total: {{total.length}}
</div>
The variable total stores the output of the slice using the as keyword.
Animation Package
1. ANGULAR 4 – OVERVIEW
Angular 4
5
Animation in Angular 4 is available as a separate package and needs to be imported from
@angular/animations. In Angular2, it was available with @angular/core. It is still kept the
same for its backward compatibility aspect.
Template
Angular 4 uses <ng-template> as the tag instead of <template>; the latter was used in
Angular2. The reason Angular 4 changed <template> to <ng-template> is because of the
name conflict of the <template> tag with the html <template> standard tag. It will
deprecate completely going ahead. This is one of the major changes in Angular 4.
TypeScript 2.2
Angular 4 is updated to a recent version of TypeScript, which is 2.2. This helps improve the
speed and gives better type checking in the project.
Pipe Title Case
Angular 4 has added a new pipe title case, which changes the first letter of each word into
uppercase.
<div>
<h2>{{ 'Angular 4 titlecase' | titlecase }}</h2>
</div>
The above line of code generates the following output – Angular 4 Titlecase.
Http Search Parameters
Search parameters to the http get api is simplified. We do not need to call URLSearchParams
for the same as was being done in Angular2.
Smaller and Faster Apps
Angular 4 applications are smaller and faster when compared to Angular2. It uses the
TypeScript version 2.2, the latest version which makes the final compilation small in size.
Angular 4
6
In this chapter, we will discuss the Environment Setup required for Angular 4. To install
Angular 4, we require the following:
 Nodejs
 Npm
 Angular CLI
 IDE for writing your code
Nodejs has to be greater than 4 and npm has to be greater than 3.
Nodejs
To check if nodejs is installed on your system, type node –v in the terminal. This will help
you see the version of nodejs currently installed on your system.
C:>node –v
v6.11.0
If it does not print anything, install nodejs on your system. To install nodejs, go the homepage
https://nodejs.org/en/download/ of nodejs and install the package based on your OS.
The homepage of nodejs will look like the following:
2. ANGULAR 4 – ENVIRONMENT SETUP
Angular 4
7
Based on your OS, install the required package. Once nodejs is installed, npm will also get
installed along with it. To check if npm is installed or not, type npm –v in the terminal. It
should display the version of the npm.
C:>npm –v
5.3.0
Angular 4 installations are very simple with the help of angular CLI. Visit the homepage
https://cli.angular.io/ of angular to get the reference of the command.
Angular 4
8
Type npm install –g @angular/cli, to install angular cli on your system.
Angular 4
9
You will get the above installation in your terminal, once Angular CLI is installed. You can use
any IDE of your choice, i.e., WebStorm, Atom, Visual Studio Code, etc.
The details of the project setup is explained in the next chapter.
Angular 4
10
AngularJS is based on the model view controller, whereas Angular 2 is based on the
components structure. Angular 4 works on the same structure as Angular2 but is faster when
compared to Angular2.
Angular4 uses TypeScript 2.1 version whereas Angular 2 uses TypeScript version 1.8. This
brings a lot of difference in the performance.
To install Angular 4, the Angular team came up with Angular CLI which eases the installation.
You need to run through a few commands to install Angular 4.
Go to this site https://cli.angular.io to install Angular CLI.
To get started with the installation, we first need to make sure we have nodejs and npm
installed with the latest version. The npm package gets installed along with nodejs.
Go to the nodejs site https://nodejs.org/en/.
3. ANGULAR 4 – PROJECT SETUP
Angular 4
11
The latest version of Nodejs v6.11.0 is recommended for users. Users who already have
nodejs greater than 4 can skip the above process. Once nodejs is installed, you can check the
version of node in the command line using the command, node –v, as shown below:
The command prompt shows v6.11.0. Once nodejs is installed, npm will also get installed
along with it.
Angular 4
12
To check the version of npm, type command npm –v in the terminal. It will display the version
of npm as shown below.
The version of npm is 3.10.10. Now that we have nodejs and npm installed, let us run the
angular cli commands to install Angular 4. You will see the following commands on the
webpage:
npm install -g @angular/cli //command to install angular 4
ng new Angular 4-app // name of the project
cd my-dream-app
ng serve
Angular 4
13
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://store.tutorialspoint.com

More Related Content

What's hot

Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting startedTejinderMakkar
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?Troy Miles
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency InjectionNir Kaufman
 
Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready Nir Kaufman
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreAri Lerner
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersQuick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersPaweł Żurowski
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App PresentationElizabeth Long
 
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...Edureka!
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2INader Debbabi
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERENadav Mary
 
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | EdurekaAngular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | EdurekaEdureka!
 
Introduction to angular 2
Introduction to angular 2Introduction to angular 2
Introduction to angular 2Dor Moshe
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkCodemotion
 
Angular Best Practices - Perfomatix
Angular Best Practices - PerfomatixAngular Best Practices - Perfomatix
Angular Best Practices - PerfomatixPerfomatix Solutions
 
How to Convert a Component Design into an MUI React Code
How to Convert a Component Design into an MUI React CodeHow to Convert a Component Design into an MUI React Code
How to Convert a Component Design into an MUI React CodeWrapPixel
 

What's hot (20)

Angular 9 New features
Angular 9 New featuresAngular 9 New features
Angular 9 New features
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting started
 
Angular material
Angular materialAngular material
Angular material
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersQuick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developers
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Angular2 tutorial
Angular2 tutorialAngular2 tutorial
Angular2 tutorial
 
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...
What's New in Angular 4 | Angular 4 Features | Angular 4 Changes | Angular Tu...
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2I
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERE
 
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | EdurekaAngular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
 
Introduction to angular 2
Introduction to angular 2Introduction to angular 2
Introduction to angular 2
 
Tech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new frameworkTech Webinar: Angular 2, Introduction to a new framework
Tech Webinar: Angular 2, Introduction to a new framework
 
Angular Best Practices - Perfomatix
Angular Best Practices - PerfomatixAngular Best Practices - Perfomatix
Angular Best Practices - Perfomatix
 
How to Convert a Component Design into an MUI React Code
How to Convert a Component Design into an MUI React CodeHow to Convert a Component Design into an MUI React Code
How to Convert a Component Design into an MUI React Code
 

Similar to Angular4 tutorial

26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]Alex Ershov
 
Angular 6 Form Validation with Material
Angular 6 Form Validation with MaterialAngular 6 Form Validation with Material
Angular 6 Form Validation with MaterialMalika Munaweera
 
Angular material tutorial
Angular material tutorialAngular material tutorial
Angular material tutorialHarikaReddy115
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular applicationSuresh Patidar
 
Angular.ppt
Angular.pptAngular.ppt
Angular.pptMytrux1
 
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdf
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdfrevolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdf
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdfRobertThorson2
 
Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAlbiorix Technology
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfiFour Technolab Pvt. Ltd.
 
agile_tutorial.pdf
agile_tutorial.pdfagile_tutorial.pdf
agile_tutorial.pdfHODCA1
 
Angular 14.pdf
Angular 14.pdfAngular 14.pdf
Angular 14.pdfSanesDm
 
Say hello world with angular 5
Say hello world with angular 5Say hello world with angular 5
Say hello world with angular 5Abhishek Mallick
 

Similar to Angular4 tutorial (20)

26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]26 top angular 8 interview questions to know in 2020   [www.full stack.cafe]
26 top angular 8 interview questions to know in 2020 [www.full stack.cafe]
 
Angular 6 Form Validation with Material
Angular 6 Form Validation with MaterialAngular 6 Form Validation with Material
Angular 6 Form Validation with Material
 
Angular material tutorial
Angular material tutorialAngular material tutorial
Angular material tutorial
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular application
 
What’s New in Angular 14?
What’s New in Angular 14?What’s New in Angular 14?
What’s New in Angular 14?
 
An Overview of Angular 4
An Overview of Angular 4 An Overview of Angular 4
An Overview of Angular 4
 
Angular.ppt
Angular.pptAngular.ppt
Angular.ppt
 
Angular
AngularAngular
Angular
 
What is Angular Ivy?
What is Angular Ivy?What is Angular Ivy?
What is Angular Ivy?
 
Angular IO
Angular IOAngular IO
Angular IO
 
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdf
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdfrevolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdf
revolutionizing-development-a-deep-dive-into-angular-v17-renaissance.pdf
 
Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web Applications
 
Learning selenium sample
Learning selenium sampleLearning selenium sample
Learning selenium sample
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdf
 
agile_tutorial.pdf
agile_tutorial.pdfagile_tutorial.pdf
agile_tutorial.pdf
 
Agile tutorial
Agile tutorialAgile tutorial
Agile tutorial
 
What are The Top Features of Angular 7?
What are The Top Features of Angular 7?What are The Top Features of Angular 7?
What are The Top Features of Angular 7?
 
Angular 14.pdf
Angular 14.pdfAngular 14.pdf
Angular 14.pdf
 
Say hello world with angular 5
Say hello world with angular 5Say hello world with angular 5
Say hello world with angular 5
 
Angular 2.0
Angular  2.0Angular  2.0
Angular 2.0
 

More from HarikaReddy115

Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorialHarikaReddy115
 
Wireless communication tutorial
Wireless communication tutorialWireless communication tutorial
Wireless communication tutorialHarikaReddy115
 
Control systems tutorial
Control systems tutorialControl systems tutorial
Control systems tutorialHarikaReddy115
 
Computer logical organization_tutorial
Computer logical organization_tutorialComputer logical organization_tutorial
Computer logical organization_tutorialHarikaReddy115
 
Computer fundamentals tutorial
Computer fundamentals tutorialComputer fundamentals tutorial
Computer fundamentals tutorialHarikaReddy115
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorialHarikaReddy115
 
Communication technologies tutorial
Communication technologies tutorialCommunication technologies tutorial
Communication technologies tutorialHarikaReddy115
 
Behavior driven development_tutorial
Behavior driven development_tutorialBehavior driven development_tutorial
Behavior driven development_tutorialHarikaReddy115
 
Basics of computers_tutorial
Basics of computers_tutorialBasics of computers_tutorial
Basics of computers_tutorialHarikaReddy115
 
Basics of computer_science_tutorial
Basics of computer_science_tutorialBasics of computer_science_tutorial
Basics of computer_science_tutorialHarikaReddy115
 
Basic electronics tutorial
Basic electronics tutorialBasic electronics tutorial
Basic electronics tutorialHarikaReddy115
 
Artificial neural network_tutorial
Artificial neural network_tutorialArtificial neural network_tutorial
Artificial neural network_tutorialHarikaReddy115
 
Artificial intelligence tutorial
Artificial intelligence tutorialArtificial intelligence tutorial
Artificial intelligence tutorialHarikaReddy115
 
Antenna theory tutorial
Antenna theory tutorialAntenna theory tutorial
Antenna theory tutorialHarikaReddy115
 
Analog communication tutorial
Analog communication tutorialAnalog communication tutorial
Analog communication tutorialHarikaReddy115
 

More from HarikaReddy115 (20)

Dbms tutorial
Dbms tutorialDbms tutorial
Dbms tutorial
 
Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorial
 
Wireless communication tutorial
Wireless communication tutorialWireless communication tutorial
Wireless communication tutorial
 
Cryptography tutorial
Cryptography tutorialCryptography tutorial
Cryptography tutorial
 
Cosmology tutorial
Cosmology tutorialCosmology tutorial
Cosmology tutorial
 
Control systems tutorial
Control systems tutorialControl systems tutorial
Control systems tutorial
 
Computer logical organization_tutorial
Computer logical organization_tutorialComputer logical organization_tutorial
Computer logical organization_tutorial
 
Computer fundamentals tutorial
Computer fundamentals tutorialComputer fundamentals tutorial
Computer fundamentals tutorial
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorial
 
Communication technologies tutorial
Communication technologies tutorialCommunication technologies tutorial
Communication technologies tutorial
 
Biometrics tutorial
Biometrics tutorialBiometrics tutorial
Biometrics tutorial
 
Behavior driven development_tutorial
Behavior driven development_tutorialBehavior driven development_tutorial
Behavior driven development_tutorial
 
Basics of computers_tutorial
Basics of computers_tutorialBasics of computers_tutorial
Basics of computers_tutorial
 
Basics of computer_science_tutorial
Basics of computer_science_tutorialBasics of computer_science_tutorial
Basics of computer_science_tutorial
 
Basic electronics tutorial
Basic electronics tutorialBasic electronics tutorial
Basic electronics tutorial
 
Auditing tutorial
Auditing tutorialAuditing tutorial
Auditing tutorial
 
Artificial neural network_tutorial
Artificial neural network_tutorialArtificial neural network_tutorial
Artificial neural network_tutorial
 
Artificial intelligence tutorial
Artificial intelligence tutorialArtificial intelligence tutorial
Artificial intelligence tutorial
 
Antenna theory tutorial
Antenna theory tutorialAntenna theory tutorial
Antenna theory tutorial
 
Analog communication tutorial
Analog communication tutorialAnalog communication tutorial
Analog communication tutorial
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Angular4 tutorial

  • 2. Angular 4 i AbouttheTutorial Angular 4 is a JavaScript framework for building web applications and apps in JavaScript, html, and TypeScript, which is a superset of JavaScript. Angular provides built-in features for animation, http service, and materials which in turn has features such as auto- complete, navigation, toolbar, menus, etc. The code is written in TypeScript, which compiles to JavaScript and displays the same in the browser. Audience This tutorial is designed for software programmers who want to learn the basics of Angular 4 and its programming concepts in a simple and easy manner. This tutorial will give you enough understanding on the various functionalities of Angular 4 with suitable examples. Prerequisites Before proceeding with this tutorial, you should have a basic understanding of HTML, CSS, JavaScript, TypeScript, and Document Object Model (DOM). Copyright&Disclaimer  Copyright 2017 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com
  • 3. Angular 4 ii TableofContents About the Tutorial ............................................................................................................................................i Audience...........................................................................................................................................................i Prerequisites.....................................................................................................................................................i Copyright & Disclaimer.....................................................................................................................................i Table of Contents ............................................................................................................................................ ii 1. Angular 4 – Overview................................................................................................................................1 Why Angular4 and Not Angular3?...................................................................................................................1 2. Angular 4 – Environment Setup ................................................................................................................3 3. Angular 4 – Project Setup..........................................................................................................................6 4. Angular 4 – Components.........................................................................................................................26 5. Angular 4 – Module.................................................................................................................................35 6. Angular 4 – Data Binding.........................................................................................................................38 7. Angular 4 – Event Binding .......................................................................................................................45 8. Angular 4 – Templates ............................................................................................................................51 9. Angular 4 – Directives .............................................................................................................................55 How to Create Custom Directives?................................................................................................................55 10. Angular 4 – Pipes ....................................................................................................................................59 How to Create a Custom Pipe?......................................................................................................................64 11. Angular 4 – Routing ................................................................................................................................67 12. Angular 4 – Services................................................................................................................................72 13. Angular 4 – Http Service..........................................................................................................................81 14. Angular 4 – Forms...................................................................................................................................88 Template Driven Form...................................................................................................................................88 Model Driven Form........................................................................................................................................91 Form Validation .............................................................................................................................................94 15. Angular 4 – Animations...........................................................................................................................99
  • 4. Angular 4 iii 16. Angular 4 – Materials............................................................................................................................105 17. Angular 4 – CLI ......................................................................................................................................114 18. Angular 4 – Examples............................................................................................................................115
  • 5. Angular 4 4 There are three major releases of Angular. The first version that was released is Angular1, which is also called AngularJS. Angular1 was followed by Angular2, which came in with a lot of changes when compared to Angular1. The structure of Angular is based on the components/services architecture. AngularJS was based on the model view controller. Angular 4 released in March 2017 proves to be a major breakthrough and is the latest release from the Angular team after Angular2. Angular 4 is almost the same as Angular 2. It has a backward compatibility with Angular 2. Projects developed in Angular 2 will work without any issues with Angular 4. Let us now see the new features and the changes made in Angular 4. WhyAngular4andNotAngular3? The Angular team faced some versioning issues internally with their modules and due to the conflict they had to move on and release the next version of Angular – the Angular4. Let us now see the new features added to Angular 4: ngIf Angular2 supported only the if condition. However, Angular 4 supports the if else condition as well. Let us see how it works using the ng-template. <span *ngIf="isavailable; else condition1">Condition is valid.</span> <ng-template #condition1>Condition is invalid</ng-template> as keyword in for loop With the help of as keyword you can store the value as shown below: <div *ngFor="let i of months | slice:0:5 as total"> Months: {{i}} Total: {{total.length}} </div> The variable total stores the output of the slice using the as keyword. Animation Package 1. ANGULAR 4 – OVERVIEW
  • 6. Angular 4 5 Animation in Angular 4 is available as a separate package and needs to be imported from @angular/animations. In Angular2, it was available with @angular/core. It is still kept the same for its backward compatibility aspect. Template Angular 4 uses <ng-template> as the tag instead of <template>; the latter was used in Angular2. The reason Angular 4 changed <template> to <ng-template> is because of the name conflict of the <template> tag with the html <template> standard tag. It will deprecate completely going ahead. This is one of the major changes in Angular 4. TypeScript 2.2 Angular 4 is updated to a recent version of TypeScript, which is 2.2. This helps improve the speed and gives better type checking in the project. Pipe Title Case Angular 4 has added a new pipe title case, which changes the first letter of each word into uppercase. <div> <h2>{{ 'Angular 4 titlecase' | titlecase }}</h2> </div> The above line of code generates the following output – Angular 4 Titlecase. Http Search Parameters Search parameters to the http get api is simplified. We do not need to call URLSearchParams for the same as was being done in Angular2. Smaller and Faster Apps Angular 4 applications are smaller and faster when compared to Angular2. It uses the TypeScript version 2.2, the latest version which makes the final compilation small in size.
  • 7. Angular 4 6 In this chapter, we will discuss the Environment Setup required for Angular 4. To install Angular 4, we require the following:  Nodejs  Npm  Angular CLI  IDE for writing your code Nodejs has to be greater than 4 and npm has to be greater than 3. Nodejs To check if nodejs is installed on your system, type node –v in the terminal. This will help you see the version of nodejs currently installed on your system. C:>node –v v6.11.0 If it does not print anything, install nodejs on your system. To install nodejs, go the homepage https://nodejs.org/en/download/ of nodejs and install the package based on your OS. The homepage of nodejs will look like the following: 2. ANGULAR 4 – ENVIRONMENT SETUP
  • 8. Angular 4 7 Based on your OS, install the required package. Once nodejs is installed, npm will also get installed along with it. To check if npm is installed or not, type npm –v in the terminal. It should display the version of the npm. C:>npm –v 5.3.0 Angular 4 installations are very simple with the help of angular CLI. Visit the homepage https://cli.angular.io/ of angular to get the reference of the command.
  • 9. Angular 4 8 Type npm install –g @angular/cli, to install angular cli on your system.
  • 10. Angular 4 9 You will get the above installation in your terminal, once Angular CLI is installed. You can use any IDE of your choice, i.e., WebStorm, Atom, Visual Studio Code, etc. The details of the project setup is explained in the next chapter.
  • 11. Angular 4 10 AngularJS is based on the model view controller, whereas Angular 2 is based on the components structure. Angular 4 works on the same structure as Angular2 but is faster when compared to Angular2. Angular4 uses TypeScript 2.1 version whereas Angular 2 uses TypeScript version 1.8. This brings a lot of difference in the performance. To install Angular 4, the Angular team came up with Angular CLI which eases the installation. You need to run through a few commands to install Angular 4. Go to this site https://cli.angular.io to install Angular CLI. To get started with the installation, we first need to make sure we have nodejs and npm installed with the latest version. The npm package gets installed along with nodejs. Go to the nodejs site https://nodejs.org/en/. 3. ANGULAR 4 – PROJECT SETUP
  • 12. Angular 4 11 The latest version of Nodejs v6.11.0 is recommended for users. Users who already have nodejs greater than 4 can skip the above process. Once nodejs is installed, you can check the version of node in the command line using the command, node –v, as shown below: The command prompt shows v6.11.0. Once nodejs is installed, npm will also get installed along with it.
  • 13. Angular 4 12 To check the version of npm, type command npm –v in the terminal. It will display the version of npm as shown below. The version of npm is 3.10.10. Now that we have nodejs and npm installed, let us run the angular cli commands to install Angular 4. You will see the following commands on the webpage: npm install -g @angular/cli //command to install angular 4 ng new Angular 4-app // name of the project cd my-dream-app ng serve
  • 14. Angular 4 13 End of ebook preview If you liked what you saw… Buy it from our store @ https://store.tutorialspoint.com