SlideShare una empresa de Scribd logo
1 de 106
Jadson Santos
Computing Engineer
Introduction to Angular
with a simple but complete project
Angular Introduction
• Angular is a framework for building client
applications in HTML, CSS and TypeScript ( that
compiles to JavaScript ).
• It has changed the way we develop client side
applications, by providing the possibilities to
apply the best practices usually applied on server
side like modular programming, separation of
concerns, testability and many other, on client
side.
2Angular
Angular Introduction
• Evolution
3Angular
Angular Introduction
• Angular is oriented to develop the front end
uncoupled of the back end
4Angular
Angular Introduction
• Traditional WEB Architecture
5Angular
Web Page
Construction
Logic
Business Logic
and
Persistence
Angular Introduction
• Service Oriented Front End Architecture - SOFEA
6Angular
HTTP Server
Services
Business Logic
and
Persistence
Angular Introduction
• SOFEA advantages
• Scalability (processing, stateless, caching)
• Interoperability (BaaS – Back-end as a Service, Web
and Mobile)
• Offline Applications
• Asynchronous development ( front-end x back-end)
7Angular
Angular Introduction
• Angular uses the concept of Single Page
Application (SPA)
• SPA is not an application of a unique html file but a fully
contained applications in the browser that do not need
to make requests for new pages on the server.
• Usually SPA makes request just of the data that will be
show inside of the pages ( accessing back end
REST+JSON services)
8Angular
Angular Introduction
• Single Page Application Advantages:
• Faster, eliminate the download of html, js and css code
in each request
• Possibility to create off line applications
9Angular
Angular Install the Environment
10Angular
Angular Install the Environment
• ATOM : Text editor (or any other that you prefer)
• Node.js + npm: dependence management (npm
~= gradle/maven in java world)
• Angular CLI: Command Line Interfaces for
angular
• TypeScript: The language of angular 2
11Angular
Angular Install the Environment
• Download and install Aton (https://atom.io/)
12Angular
Angular Install the Environment
• Aton Plugins: Aton -> Settings -> Install
• atom-typescript
• file-icons
• angular-2-typeScript-snippets
13Angular
Angular Install the Environment
• Download and install Node.js (https://nodejs.org)
to have access to npm
14Angular
Angular Install the Environment
• After install npm, install typescript and angular cli
using the npm of node.js
• sudo npm intall –g typescript
• sudo npm intall –g @angular/cli
15Angular
Angular Install the Environment
16Angular
• Checking
Angular Create a new Project
17Angular
Angular Create a new Project
18Angular
• Create a new angular project
• ng new project_name
Angular Create a new Project
19Angular
• Open angular project in Atom
Angular Create the Project
• Running the project
• ng server inside of project folder
• open the browser on http://localhost:4200
20Angular
Angular Create a new Project
• Default Angular Page
21Angular
Angular Creating Components
22Angular
Angular Creating Components
• Angular is based on components.
• There is already the main component called
app.component that shows the “Wellcome to App” page
when you access localhost:4200
23Angular
Angular Creating Components
• Angular component have 3 basics parts.
• name-component.html (the html code of component)
• name-component.css (css style of component)
• name-component.ts (the typescritp of component)
24Angular
Angular Creating Components
• Our application will have 3 components
• Let's create then with ng g c name Angular CLI
command
25Angular
Header
Home
Footer
Angular Creating Components
• Create Angular components
• ng g c header
• ng g c home
• ng g c footer
26Angular
Angular Creating Components
• Each component has a simple html page
27Angular
Angular Creating Components
• A empty css file
28Angular
Angular Creating Components
• And a typescript class
29Angular
Angular Creating Components
• Each component has a selector in the typescript
class that identify the component
30Angular
Angular Creating Components
• So, let’s erase the content of the template
app.component.html file and put our components
selectors in the order of the components will be
shown
31Angular
Angular Creating Components
• ng server to run the development angular server
32Angular
Angular Project Look and Feel
33Angular
Angular Project Look and Feel
• Now let’s install bootstrap in our project to make
view pretty
• To install new angular external modules use npm
npm install bootstrap@3 jquery --save
• This installs Bootstrap and jQuery into the
node_modules folder within the project directory
34Angular
Angular Project Look and Feel
• When we are development a web application with
bootstrap and jquery we need to include its .css
and .js files in our html pages.
• We can do this with angular, but usually angular
has a file .angular-cli.json where we can include
the .css and .javascript code that we will use in
our project
35Angular
Angular Project Look and Feel
• Open the .angular-cli.json file and add the css
and js files of bootstrap and jQuery inside slyles
and scripts arrays.
36Angular
Angular Project Look and Feel
• Now we can open the home component template
(html file) and use some bootstrap css class
37Angular
Angular Project Look and Feel
• The page will use bootstrap css style:
38Angular
Angular Project Look and Feel
• We can also use bootstrap templates in our
project
• Angular projects have a assets folder that we
can use to put static files, like images, html
templates, etc..
• Let’s use in our project the SB Admin 2 bootstrap
theme (https://startbootstrap.com/template-
overviews/sb-admin-2/)
39Angular
Angular Project Look and Feel
• Adding the SB Admin 2 bootstrap theme
• Download it
40Angular
Angular Project Look and Feel
• Adding the SB Admin 2 bootstrap theme
• Copy it content to the assets directory
41Angular
Angular Project Look and Feel
• Adding the SB Admin 2 bootstrap theme
• Add its js and css files in the .angular-cli.json file
42Angular
Angular Project Look and Feel
• Adding the SB Admin 2 bootstrap theme
• Now we can use SB Admin 2 elements in the angular
components html files
43Angular
Angular Data Binding
44Angular
Angular Data Binding
• Interpolation
• Allows us to read primitive or object values from
component properties in the template (html file)
45Angular
Angular Data Binding
• Property Binding
• Angular executes the expression and assigns it to a
property of an HTML element, a component, or a
directive.
46Angular
Angular Data Binding
• Event Binding
• A component method responds to an event raised by an
element, component, or directive.
47Angular
Angular Data Binding
• Two-Way Data Binding
• Its takes a combination of setting a specific element
property and listening for an element change event.
48Angular
Angular Data Binding
• Two-Way Data Binding
• You can use a property + event binding
• Or [ ( ) ] syntax
49Angular
Angular Data Binding
50Angular
Angular Directives
51Angular
Angular Directives
• Attribute Directives and Structural Directives
• Attribute Directives: changes the appearance or
behavior of a DOM element
• Structural Directives: Change the DOM's structure,
typically by adding, removing, or manipulating elements.
52Angular
Angular Directives
• ngIf
53Angular
Angular Directives
• ngFor
54Angular
Angular Directives
55Angular
Angular Communicate with back end
56Angular
Angular Communicate with back end
• To communication with back end angular uses
the concept of “services”
• Creating a new service
• cd src/app/home
• ng g s home
• This create inside of home
• folder the home.service.ts
• file
57Angular
Angular Communicate with back end
• In the HomeService
• import the HttpClient from “@angular/commum/http”
• Inject it by constructor
• Create a method getScearios()
• In the method getScenarios() call the get method
passing the URL of the service
• This call a REST service in the backend that will return a
array of scenarios using json.
58Angular
Angular Communicate with back end
• HomeService
59Angular
Angular Communicate with back end
• HomeService
60Angular
Angular Communicate with back end
• In the HomeComponent
• import the HttpService from ./home.service
• Inject it by constructor
• Create a method scenariosList() that call the
getScearios() from the service
• On the ngOnInit() method call the scenariosList(),
when the home component is create (the html code is
show)
• ngOnInit() -> sceneariosList() -> getScenarios()
61Angular
Angular Communicate with back end
• HomeComponent
62Angular
Angular Communicate with back end
• HomeComponent
63Angular
Angular Communicate with back end
• In app module (app.module.ts file)
• import the HttpClientModule and the HomeService
• add HttpClientModule in imports[] arrays and
HomeService in providers[] array
64Angular
Angular Communicate with back end
• In the app module (app.module.ts file)
65Angular
Angular Communicate with back end
• In the back end you can use any technology
• We create a RestFul Web Service using Spring
that return a list of ScenarioDTO objects
66Angular
Angular Communicate with back end
• Back end
67Angular
Angular Communicate with back end
• The Scenario[] arrays return by getScenarios()
method of HomeService will have fields with the
same name of ScenarioDTO return by back end.
68Angular
Angular Communicate with back end
• Now on the front end, you can iterate over the
array on the home template (.html file) using
ngFor directive and access the fields defined on
back end.
69Angular
Angular Communicate with back end
• Now on the front end, you can iterate over the
array on the home template (.html file) using
ngFor directive and access the fields defined on
back end.
70Angular
Angular Routes
71Angular
Angular Routes
• Routes is a functionally that helps your
application to become a Single Page Application
• It redirect the user to another component without
reload the page or call the back end.
72Angular
Angular Routes
• We create 2 new components charts and
scenarios
• And a new file app.routing.ts
73Angular
Angular Routes
• In the file app.routing.ts we will declare the root
routes of our application
74Angular
Angular Routes
• Declare a appRoutes variable of the type Routes
that is a array with two fields: the path and the
component
• When access one path the application will
redirect for the component
75Angular
Angular Routes
• Declare a const with the routes for root routes
76Angular
Angular Routes
• And import this const in the app.module.ts
77Angular
Angular Routes
• Now we have to indicate where the html code of
component will be drawn in our application
• We will indicate this with router-outlet tag.
• We put this tag on the app.component.html
78Angular
Angular Routes
• In the Home component we will let just the
common code.
• When the user access the path “/scenarios”, the
code of ScenariosComponent will be rendered in
app.component.html
• When the user access the path “/charts”, the
code of ChartsComponent will be rendered in
app.component.html.
79Angular
Angular Routes
• Accessing the path “”
80Angular
Angular Routes
• Accessing the path “/scenarios”
81Angular
Angular Routes
• Accessing the path “/charts”
82Angular
Angular Routes
• We can redirect from a link without reload the
page using the directive routerLink
83Angular
Angular Versioning the Project
84Angular
Angular Versioning the Project
• Angular/cli automatically create a .gitignore file
that ignore the node_modules directory
85Angular
Angular Versioning the Project
• This happens because this directory contains all
dependence of project and is very big.
• When you clone a angular project ( that should
not contains the node_modules), you can restore
it with the command npm install.
• git clone url_to_my_project
• cd project_directory
• npm install
• ng server
86Angular
Angular Environment Variables
87Angular
Angular Environment Variables
• You can manage different environments
• Angular create under src directory, a directory
named environments, where you can configure
global constants
88Angular
Angular Environment Variables
• Define the environments that you will have in
environments array in .angular-cli.json file:
89Angular
Angular Environment Variables
• environment.ts is default environment
• You can specify the environment on the moment
of the build
• ng build --env=test
• This is very useful to define the api url.
90Angular
Angular Environment Variables
• You can import env file in components, services,
etc…, like this:
91Angular
Angular Build to Production
92Angular
Angular Build to Production
• Edit the index.html to set the <base href>
appropriately with the context of the application,
ending with “/”.
93Angular
Angular Build to Production
• To build the project to production, we use this
command:
ng build --prod --env=prod
• The prod option will minify all files and do another cool
things to format the files do production.
• The env option will build the correct environment file to
use
94Angular
Angular Build to Production
• The build will generated a dist directory
95Angular
Angular Build to Production
• Rename the dist directory as application context
name (same name of base href in index.html)
• Copy the directory put inside a HTTP Server
(apache, tomcat, etc)
96Angular
Angular Build to Production
97Angular
Angular Commands Summary
98Angular
• ng new name (create a new project)
• npm install (download all dependences and restore
node_modules directory)
• ng server (run the application for development
localhost:4200)
• ng g m name (generate a new module)
• ng g c name (generate a new component)
• ng g s name (generate a new server)
• ng build --prod --env=prod (build for production)
Angular Project Structure Overview
99Angular
Declaration of angular dependences
Configuration of your project
The code of our application
Contains all dependences
Git control Version
end to end tests
build output folder
Angular Project Structure (Inside src folder)
100Angular
index.html of our application
The icon of our application
configuration to different environments (dev, test e prod)
Global CSS styles can be put here
Images and other things can be put here
Our code
Angular Project Structure (Inside app folder)
101Angular
The main component (mandatory)
Our specific components
The main model (mandatory)
Source Code
102Angular
• https://github.com/jadsonjs/angular/tree/master/k
ootenai-web
• Pictures take from
• https://visualwebz.com/front-end-vs-back-end-
developers/
• http://www.cvivas.com/development-test-production-
environments/
• http://cafecomcodig0.com.br/o-que-e-back-end-e-front-
end/
• https://www.entrepreneur.com/article/286256
• http://www.datacenterdynamics.com.br/focus/archive/20
17/02/aumento-da-complexidade-e-custo-de-ti-
estimula-demanda-por-serviços-de-data-ce
103Angular
• Pictures take from
• http://meneleu.blogspot.com.br/2015/08/como-voce-
pode-impedir-manipulacao.html
• https://www.infragistics.com/community/blogs/dhananja
y_kumar/archive/2016/12/12/simplifying-two-way-data-
binding-in-angular-2.aspx
104Angular
• References
• http://cafe.algaworks.com/oficina-angular-rest-spring-
boot/
• https://medium.com/codingthesmartway-com-
blog/using-bootstrap-with-angular-c83c3cee3f4a
• https://loiane.training/course/angular-2/
• https://startbootstrap.com/template-overviews/sb-
admin-2/
• https://medium.com/beautiful-angular/angular-2-and-
environment-variables-59c57ba643be
• https://angular.io/tutorial
105Angular
• References
• https://imasters.com.br/desenvolvimento/single-page-
applications-e-outras-maravilhas-da-web-
moderna/?trace=1519021197
• https://blog.angular-university.io/angular-2-ngfor/
106Angular

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Angular
AngularAngular
Angular
 
Angular
AngularAngular
Angular
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Angular 14.pptx
Angular 14.pptxAngular 14.pptx
Angular 14.pptx
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
.Net Core
.Net Core.Net Core
.Net Core
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
What’s New in Angular 14?
What’s New in Angular 14?What’s New in Angular 14?
What’s New in Angular 14?
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Introduzione ad angular 7/8
Introduzione ad angular 7/8Introduzione ad angular 7/8
Introduzione ad angular 7/8
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 

Similar a Introduction to angular with a simple but complete project

4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 

Similar a Introduction to angular with a simple but complete project (20)

Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
 
Angular IO
Angular IOAngular IO
Angular IO
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
 
Angular
AngularAngular
Angular
 
Mastering angular - Dot Net Tricks
Mastering angular - Dot Net TricksMastering angular - Dot Net Tricks
Mastering angular - Dot Net Tricks
 
Building Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET CoreBuilding Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET Core
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Angular 2.0
Angular  2.0Angular  2.0
Angular 2.0
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
End to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJS
 
Advanced AngularJS Tips and Tricks
Advanced AngularJS Tips and TricksAdvanced AngularJS Tips and Tricks
Advanced AngularJS Tips and Tricks
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptx
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular application
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
TechEvent 2019: Nachhaltige Client-Architekturen mit Angular Elements; Thomas...
TechEvent 2019: Nachhaltige Client-Architekturen mit Angular Elements; Thomas...TechEvent 2019: Nachhaltige Client-Architekturen mit Angular Elements; Thomas...
TechEvent 2019: Nachhaltige Client-Architekturen mit Angular Elements; Thomas...
 
What's new in Angular 2?
What's new in Angular 2?What's new in Angular 2?
What's new in Angular 2?
 

Más de Jadson Santos

A Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring PracticesA Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring Practices
Jadson Santos
 
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Jadson Santos
 

Más de Jadson Santos (19)

A Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring PracticesA Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring Practices
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
 
Continuous Delivery with Jenkins
Continuous Delivery with JenkinsContinuous Delivery with Jenkins
Continuous Delivery with Jenkins
 
Cd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and Heroku
 
Vue.js
Vue.jsVue.js
Vue.js
 
Jenkins Continuous Delivery
Jenkins Continuous DeliveryJenkins Continuous Delivery
Jenkins Continuous Delivery
 
Hazelcast Distributed Lock
Hazelcast Distributed LockHazelcast Distributed Lock
Hazelcast Distributed Lock
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Testes Unitários
Testes UnitáriosTestes Unitários
Testes Unitários
 
Java8
Java8Java8
Java8
 
Gradle
GradleGradle
Gradle
 
Git
GitGit
Git
 
Introdução ao Flyway
Introdução ao FlywayIntrodução ao Flyway
Introdução ao Flyway
 
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
 
Usando hiberante de forma otimizada
Usando hiberante de forma otimizadaUsando hiberante de forma otimizada
Usando hiberante de forma otimizada
 
Usando JMeter para testar sua aplicação JSF
Usando JMeter para testar sua aplicação JSFUsando JMeter para testar sua aplicação JSF
Usando JMeter para testar sua aplicação JSF
 
ICEIS 2013 Presentation
ICEIS 2013 PresentationICEIS 2013 Presentation
ICEIS 2013 Presentation
 
Enums
EnumsEnums
Enums
 
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Último (20)

Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 

Introduction to angular with a simple but complete project

  • 1. Jadson Santos Computing Engineer Introduction to Angular with a simple but complete project
  • 2. Angular Introduction • Angular is a framework for building client applications in HTML, CSS and TypeScript ( that compiles to JavaScript ). • It has changed the way we develop client side applications, by providing the possibilities to apply the best practices usually applied on server side like modular programming, separation of concerns, testability and many other, on client side. 2Angular
  • 4. Angular Introduction • Angular is oriented to develop the front end uncoupled of the back end 4Angular
  • 5. Angular Introduction • Traditional WEB Architecture 5Angular Web Page Construction Logic Business Logic and Persistence
  • 6. Angular Introduction • Service Oriented Front End Architecture - SOFEA 6Angular HTTP Server Services Business Logic and Persistence
  • 7. Angular Introduction • SOFEA advantages • Scalability (processing, stateless, caching) • Interoperability (BaaS – Back-end as a Service, Web and Mobile) • Offline Applications • Asynchronous development ( front-end x back-end) 7Angular
  • 8. Angular Introduction • Angular uses the concept of Single Page Application (SPA) • SPA is not an application of a unique html file but a fully contained applications in the browser that do not need to make requests for new pages on the server. • Usually SPA makes request just of the data that will be show inside of the pages ( accessing back end REST+JSON services) 8Angular
  • 9. Angular Introduction • Single Page Application Advantages: • Faster, eliminate the download of html, js and css code in each request • Possibility to create off line applications 9Angular
  • 10. Angular Install the Environment 10Angular
  • 11. Angular Install the Environment • ATOM : Text editor (or any other that you prefer) • Node.js + npm: dependence management (npm ~= gradle/maven in java world) • Angular CLI: Command Line Interfaces for angular • TypeScript: The language of angular 2 11Angular
  • 12. Angular Install the Environment • Download and install Aton (https://atom.io/) 12Angular
  • 13. Angular Install the Environment • Aton Plugins: Aton -> Settings -> Install • atom-typescript • file-icons • angular-2-typeScript-snippets 13Angular
  • 14. Angular Install the Environment • Download and install Node.js (https://nodejs.org) to have access to npm 14Angular
  • 15. Angular Install the Environment • After install npm, install typescript and angular cli using the npm of node.js • sudo npm intall –g typescript • sudo npm intall –g @angular/cli 15Angular
  • 16. Angular Install the Environment 16Angular • Checking
  • 17. Angular Create a new Project 17Angular
  • 18. Angular Create a new Project 18Angular • Create a new angular project • ng new project_name
  • 19. Angular Create a new Project 19Angular • Open angular project in Atom
  • 20. Angular Create the Project • Running the project • ng server inside of project folder • open the browser on http://localhost:4200 20Angular
  • 21. Angular Create a new Project • Default Angular Page 21Angular
  • 23. Angular Creating Components • Angular is based on components. • There is already the main component called app.component that shows the “Wellcome to App” page when you access localhost:4200 23Angular
  • 24. Angular Creating Components • Angular component have 3 basics parts. • name-component.html (the html code of component) • name-component.css (css style of component) • name-component.ts (the typescritp of component) 24Angular
  • 25. Angular Creating Components • Our application will have 3 components • Let's create then with ng g c name Angular CLI command 25Angular Header Home Footer
  • 26. Angular Creating Components • Create Angular components • ng g c header • ng g c home • ng g c footer 26Angular
  • 27. Angular Creating Components • Each component has a simple html page 27Angular
  • 28. Angular Creating Components • A empty css file 28Angular
  • 29. Angular Creating Components • And a typescript class 29Angular
  • 30. Angular Creating Components • Each component has a selector in the typescript class that identify the component 30Angular
  • 31. Angular Creating Components • So, let’s erase the content of the template app.component.html file and put our components selectors in the order of the components will be shown 31Angular
  • 32. Angular Creating Components • ng server to run the development angular server 32Angular
  • 33. Angular Project Look and Feel 33Angular
  • 34. Angular Project Look and Feel • Now let’s install bootstrap in our project to make view pretty • To install new angular external modules use npm npm install bootstrap@3 jquery --save • This installs Bootstrap and jQuery into the node_modules folder within the project directory 34Angular
  • 35. Angular Project Look and Feel • When we are development a web application with bootstrap and jquery we need to include its .css and .js files in our html pages. • We can do this with angular, but usually angular has a file .angular-cli.json where we can include the .css and .javascript code that we will use in our project 35Angular
  • 36. Angular Project Look and Feel • Open the .angular-cli.json file and add the css and js files of bootstrap and jQuery inside slyles and scripts arrays. 36Angular
  • 37. Angular Project Look and Feel • Now we can open the home component template (html file) and use some bootstrap css class 37Angular
  • 38. Angular Project Look and Feel • The page will use bootstrap css style: 38Angular
  • 39. Angular Project Look and Feel • We can also use bootstrap templates in our project • Angular projects have a assets folder that we can use to put static files, like images, html templates, etc.. • Let’s use in our project the SB Admin 2 bootstrap theme (https://startbootstrap.com/template- overviews/sb-admin-2/) 39Angular
  • 40. Angular Project Look and Feel • Adding the SB Admin 2 bootstrap theme • Download it 40Angular
  • 41. Angular Project Look and Feel • Adding the SB Admin 2 bootstrap theme • Copy it content to the assets directory 41Angular
  • 42. Angular Project Look and Feel • Adding the SB Admin 2 bootstrap theme • Add its js and css files in the .angular-cli.json file 42Angular
  • 43. Angular Project Look and Feel • Adding the SB Admin 2 bootstrap theme • Now we can use SB Admin 2 elements in the angular components html files 43Angular
  • 45. Angular Data Binding • Interpolation • Allows us to read primitive or object values from component properties in the template (html file) 45Angular
  • 46. Angular Data Binding • Property Binding • Angular executes the expression and assigns it to a property of an HTML element, a component, or a directive. 46Angular
  • 47. Angular Data Binding • Event Binding • A component method responds to an event raised by an element, component, or directive. 47Angular
  • 48. Angular Data Binding • Two-Way Data Binding • Its takes a combination of setting a specific element property and listening for an element change event. 48Angular
  • 49. Angular Data Binding • Two-Way Data Binding • You can use a property + event binding • Or [ ( ) ] syntax 49Angular
  • 52. Angular Directives • Attribute Directives and Structural Directives • Attribute Directives: changes the appearance or behavior of a DOM element • Structural Directives: Change the DOM's structure, typically by adding, removing, or manipulating elements. 52Angular
  • 56. Angular Communicate with back end 56Angular
  • 57. Angular Communicate with back end • To communication with back end angular uses the concept of “services” • Creating a new service • cd src/app/home • ng g s home • This create inside of home • folder the home.service.ts • file 57Angular
  • 58. Angular Communicate with back end • In the HomeService • import the HttpClient from “@angular/commum/http” • Inject it by constructor • Create a method getScearios() • In the method getScenarios() call the get method passing the URL of the service • This call a REST service in the backend that will return a array of scenarios using json. 58Angular
  • 59. Angular Communicate with back end • HomeService 59Angular
  • 60. Angular Communicate with back end • HomeService 60Angular
  • 61. Angular Communicate with back end • In the HomeComponent • import the HttpService from ./home.service • Inject it by constructor • Create a method scenariosList() that call the getScearios() from the service • On the ngOnInit() method call the scenariosList(), when the home component is create (the html code is show) • ngOnInit() -> sceneariosList() -> getScenarios() 61Angular
  • 62. Angular Communicate with back end • HomeComponent 62Angular
  • 63. Angular Communicate with back end • HomeComponent 63Angular
  • 64. Angular Communicate with back end • In app module (app.module.ts file) • import the HttpClientModule and the HomeService • add HttpClientModule in imports[] arrays and HomeService in providers[] array 64Angular
  • 65. Angular Communicate with back end • In the app module (app.module.ts file) 65Angular
  • 66. Angular Communicate with back end • In the back end you can use any technology • We create a RestFul Web Service using Spring that return a list of ScenarioDTO objects 66Angular
  • 67. Angular Communicate with back end • Back end 67Angular
  • 68. Angular Communicate with back end • The Scenario[] arrays return by getScenarios() method of HomeService will have fields with the same name of ScenarioDTO return by back end. 68Angular
  • 69. Angular Communicate with back end • Now on the front end, you can iterate over the array on the home template (.html file) using ngFor directive and access the fields defined on back end. 69Angular
  • 70. Angular Communicate with back end • Now on the front end, you can iterate over the array on the home template (.html file) using ngFor directive and access the fields defined on back end. 70Angular
  • 72. Angular Routes • Routes is a functionally that helps your application to become a Single Page Application • It redirect the user to another component without reload the page or call the back end. 72Angular
  • 73. Angular Routes • We create 2 new components charts and scenarios • And a new file app.routing.ts 73Angular
  • 74. Angular Routes • In the file app.routing.ts we will declare the root routes of our application 74Angular
  • 75. Angular Routes • Declare a appRoutes variable of the type Routes that is a array with two fields: the path and the component • When access one path the application will redirect for the component 75Angular
  • 76. Angular Routes • Declare a const with the routes for root routes 76Angular
  • 77. Angular Routes • And import this const in the app.module.ts 77Angular
  • 78. Angular Routes • Now we have to indicate where the html code of component will be drawn in our application • We will indicate this with router-outlet tag. • We put this tag on the app.component.html 78Angular
  • 79. Angular Routes • In the Home component we will let just the common code. • When the user access the path “/scenarios”, the code of ScenariosComponent will be rendered in app.component.html • When the user access the path “/charts”, the code of ChartsComponent will be rendered in app.component.html. 79Angular
  • 80. Angular Routes • Accessing the path “” 80Angular
  • 81. Angular Routes • Accessing the path “/scenarios” 81Angular
  • 82. Angular Routes • Accessing the path “/charts” 82Angular
  • 83. Angular Routes • We can redirect from a link without reload the page using the directive routerLink 83Angular
  • 84. Angular Versioning the Project 84Angular
  • 85. Angular Versioning the Project • Angular/cli automatically create a .gitignore file that ignore the node_modules directory 85Angular
  • 86. Angular Versioning the Project • This happens because this directory contains all dependence of project and is very big. • When you clone a angular project ( that should not contains the node_modules), you can restore it with the command npm install. • git clone url_to_my_project • cd project_directory • npm install • ng server 86Angular
  • 88. Angular Environment Variables • You can manage different environments • Angular create under src directory, a directory named environments, where you can configure global constants 88Angular
  • 89. Angular Environment Variables • Define the environments that you will have in environments array in .angular-cli.json file: 89Angular
  • 90. Angular Environment Variables • environment.ts is default environment • You can specify the environment on the moment of the build • ng build --env=test • This is very useful to define the api url. 90Angular
  • 91. Angular Environment Variables • You can import env file in components, services, etc…, like this: 91Angular
  • 92. Angular Build to Production 92Angular
  • 93. Angular Build to Production • Edit the index.html to set the <base href> appropriately with the context of the application, ending with “/”. 93Angular
  • 94. Angular Build to Production • To build the project to production, we use this command: ng build --prod --env=prod • The prod option will minify all files and do another cool things to format the files do production. • The env option will build the correct environment file to use 94Angular
  • 95. Angular Build to Production • The build will generated a dist directory 95Angular
  • 96. Angular Build to Production • Rename the dist directory as application context name (same name of base href in index.html) • Copy the directory put inside a HTTP Server (apache, tomcat, etc) 96Angular
  • 97. Angular Build to Production 97Angular
  • 98. Angular Commands Summary 98Angular • ng new name (create a new project) • npm install (download all dependences and restore node_modules directory) • ng server (run the application for development localhost:4200) • ng g m name (generate a new module) • ng g c name (generate a new component) • ng g s name (generate a new server) • ng build --prod --env=prod (build for production)
  • 99. Angular Project Structure Overview 99Angular Declaration of angular dependences Configuration of your project The code of our application Contains all dependences Git control Version end to end tests build output folder
  • 100. Angular Project Structure (Inside src folder) 100Angular index.html of our application The icon of our application configuration to different environments (dev, test e prod) Global CSS styles can be put here Images and other things can be put here Our code
  • 101. Angular Project Structure (Inside app folder) 101Angular The main component (mandatory) Our specific components The main model (mandatory)
  • 103. • Pictures take from • https://visualwebz.com/front-end-vs-back-end- developers/ • http://www.cvivas.com/development-test-production- environments/ • http://cafecomcodig0.com.br/o-que-e-back-end-e-front- end/ • https://www.entrepreneur.com/article/286256 • http://www.datacenterdynamics.com.br/focus/archive/20 17/02/aumento-da-complexidade-e-custo-de-ti- estimula-demanda-por-serviços-de-data-ce 103Angular
  • 104. • Pictures take from • http://meneleu.blogspot.com.br/2015/08/como-voce- pode-impedir-manipulacao.html • https://www.infragistics.com/community/blogs/dhananja y_kumar/archive/2016/12/12/simplifying-two-way-data- binding-in-angular-2.aspx 104Angular
  • 105. • References • http://cafe.algaworks.com/oficina-angular-rest-spring- boot/ • https://medium.com/codingthesmartway-com- blog/using-bootstrap-with-angular-c83c3cee3f4a • https://loiane.training/course/angular-2/ • https://startbootstrap.com/template-overviews/sb- admin-2/ • https://medium.com/beautiful-angular/angular-2-and- environment-variables-59c57ba643be • https://angular.io/tutorial 105Angular