SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Angular 4 for Java
Developers
Yakov Fain
Farata Systems

yfain
By the end of this presentation you
won’t become an Angular expert,
but you’ll start being dangerous!
The Legal Slide
About myself
• Work for Farata Systems 

Angular practice lead
• Java Champion
• Latest book:

“Angular Development with TypeScript”
ctwdevoxxus

40% off
Agenda
• High-level overview of the Angular framework and TypeScript
• Generating and bundling a project with Angular CLI
• Start a Java REST service with Spring Boot
• Create an Angular REST client and deploy it under Spring
Boot
• Demo of a sample Angular app that uses REST and
WebSockets
Angular Framework
• Component-based (not MVC)
• Dependency Injection
• Router
• Integrated RxJS
• Can write apps in TypeScript, Dart, or JavaScript
• UI components: Angular Material 2
• The rendering engine
The landing page of an Auction app
An app is a tree of components
HTML
import {Component} from '@angular/core';

import {Product, ProductService} from '../services/product-service';



@Component({

selector: 'app-root', 

templateUrl: 'application.html',

styleUrls: ['application.css']

})

export class AppComponent {

products: Array<Product> = []; 



constructor(private productService: ProductService) { 

this.products = this.productService.getProducts(); 

}

}
HTML, CSS
TypeScript
TypeScript

for Java Developers
Arrow Function Expressions
let getName = () => 'John Smith';
console.log(`The name is ` + getName());
Anonymous

function
A Class With Constructor
TypeScript JavaScript (ES5)
Inheritance
Classical Prototypal
Generics
Compile time error
No Errors
Interfaces
No interfaces
in JavaScript
Angular CLI
What’s Angular CLI
• Scaffolding the project and creating a basic app
• Generating components, services, modules, etc.
• Serving the app to the browser
• Bundling apps for dev and prod deployments
• Generates boilerplate unit tests and configures test
runners
Demo
- Generating a new project

- Dev and prod builds with Angular CLI
Single Page Apps
Router’s features
- Pass data to routes
- Child component can have their routes
- Multiple router outlets
- Guarding routes
- Lazy loading of modules
Dependency Injection
• Angular injects values into components via constructors
• Each component has its own injector
• You specify a provider so Angular knows what to inject
A sample injectable service
@Injectable()
export class ProductService{


getProducts(): Product {

// An HTTP request can go here 



return new Product( 0, "iPhone 7", 249.99, "The latest iPhone, 7-inch screen");

}

}
Injecting the ProductService
import {Component} from ‘@angular/core';

import {ProductService, Product} from “./product.service";



@Component({

selector: 'di-product-page',

template: `<div>

<h1>Product Details</h1>

<h2>Title: {{product.title}}</h2>

<h2>Description: {{product.description}}</h2>

<h2>Price: ${{product.price}}</h2>

</div>`,

providers:[ProductService]

})



export class ProductComponent {

product: Product;



constructor( productService: ProductService ) {

this.product = productService.getProduct();

}

}
Injection
Reactive Programming: Push
Subscribe to messages from Observable and handle them by Observer
Observer
Subscriber
Observer
Subscriber
push
push
push
Observer
Subscriber
Observable
Data

Source
Reactive programming in Angular
- Router

- Reactive Forms

- EventEmitter (a subclass of Subject)
- Handling HTTP responses

- WebSockets
Http and Observables


class AppComponent implements OnInit{



products: Array = [];



constructor(private http: Http) {}
ngOnInit() {

this.http.get(‘/api/products’)

.map(res => res.json()) // Turn JSON from HTTP response into JS obj

.subscribe(

data => {



this.products=data;

},



err =>

console.log("Can't get products. Error code: %s, URL: %s ",

err.status, err.url),



() => console.log('Product(s) are retrieved')

);

}

}
O
b
s
e
r
v
e
r
Inter-component
communications
@Input properties
@Component({

selector: 'order-processor',

template: `...`

})
class OrderComponent {



@Input() quantity: number;



@Input()

set stockSymbol(value: string) {

// process the stockSymbol change here

}

<order-processor [stockSymbol]="stock" quantity="100"></order-processor>
Child
Parent
@Output properties
class PriceQuoterComponent {



@Output() lastPrice: EventEmitter <IPriceQuote> = new EventEmitter();



stockSymbol: string = "IBM";



constructor() {

setInterval(() => {

let priceQuote: IPriceQuote = {

stockSymbol: this.stockSymbol,

lastPrice: 100*Math.random()

};



this.lastPrice.emit(priceQuote);



}, 1000);

}

}
<price-quoter (lastPrice)="priceQuoteHandler($event)"></price-quoter><br>
Child
Parent
An injectable service as a mediator
Forms API
- Template-driven forms
- Reactive forms
- Form validation
A template-driven form
@Component({

selector: 'app-root',

template: `

<form #f="ngForm" (ngSubmit)="onSubmit(f.value)">

<div>Username: <input type="text" name="username" ngModel></div>

<div>SSN: <input type="text" name="ssn" ngModel></div>

<div>Password: <input type="password" name="password" ngModel></div>

<div>Confirm password: <input type="password" name="pconfirm" ngModel></div>

<button type="submit">Submit</button>

</form>

`

})

export class AppComponent {

onSubmit(formData) {

console.log(formData);

}

}
"scripts": {



"start": "ng serve --proxy-config proxy.conf.json",



"build": "ng build -prod",



"postbuild": "npm run deploy”,


"predeploy": "rimraf ../server/build/public
&& mkdirp ../server/build/public”,


"deploy": "copyfiles -f dist/** ../server/build/public"

}
Automating deployments with
npm scripts
static

resources
Demo

Angular + Spring Boot
Java
Angular
Designed in 1995 in Norway (still alive)
What’s Material Design?
Material design is visual language (a spec) that defines
the classic principles of good design.
Palettes
Angular Material 2
Need more components? Use the library PrimeNG
Demo
Thank you!
• The book code samples:

https://github.com/Farata/angular2typescript
• Training inquiries: 

training@faratasystems.com
• My blog:

yakovfain.com
• Twitter: @yfain

ctwdevoxxus

40% off

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
AngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLIAngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLI
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
Angular JS, steal the idea
Angular JS, steal the ideaAngular JS, steal the idea
Angular JS, steal the idea
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with 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 js
Angular jsAngular js
Angular js
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 

Destaque

Destaque (8)

Developing a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2IDeveloping a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2I
 
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java Developers
 
An Overview of Angular 4
An Overview of Angular 4 An Overview of Angular 4
An Overview of Angular 4
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2I
 
Alphorm.com Formation Angular - Les fondamentaux
Alphorm.com Formation Angular - Les fondamentauxAlphorm.com Formation Angular - Les fondamentaux
Alphorm.com Formation Angular - Les fondamentaux
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
 

Semelhante a Angular 4 for Java Developers

What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
Alfonso Fernández
 

Semelhante a Angular 4 for Java Developers (20)

angular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptxangular-concepts-introduction-slides.pptx
angular-concepts-introduction-slides.pptx
 
mean stack
mean stackmean stack
mean stack
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web Services
 
angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdf
 
Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 
Angular 2 - a New Hope
Angular 2 - a New HopeAngular 2 - a New Hope
Angular 2 - a New Hope
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
 
Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6
 
Angular IO
Angular IOAngular IO
Angular IO
 
Angular resolver tutorial
Angular resolver tutorialAngular resolver tutorial
Angular resolver tutorial
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
 

Mais de Yakov Fain

Mais de Yakov Fain (16)

Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
 
Using JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot appsUsing JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot apps
 
Reactive programming in Angular 2
Reactive programming in Angular 2Reactive programming in Angular 2
Reactive programming in Angular 2
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello World
 
Running a Virtual Company
Running a Virtual CompanyRunning a Virtual Company
Running a Virtual Company
 
Princeton jug git_github
Princeton jug git_githubPrinceton jug git_github
Princeton jug git_github
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
Surviving as a Professional Software Developer
Surviving as a Professional Software DeveloperSurviving as a Professional Software Developer
Surviving as a Professional Software Developer
 
Becoming a professional software developer
Becoming a professional software developerBecoming a professional software developer
Becoming a professional software developer
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Angular 4 for Java Developers

  • 1. Angular 4 for Java Developers Yakov Fain Farata Systems
 yfain
  • 2. By the end of this presentation you won’t become an Angular expert, but you’ll start being dangerous! The Legal Slide
  • 3. About myself • Work for Farata Systems 
 Angular practice lead • Java Champion • Latest book:
 “Angular Development with TypeScript” ctwdevoxxus
 40% off
  • 4. Agenda • High-level overview of the Angular framework and TypeScript • Generating and bundling a project with Angular CLI • Start a Java REST service with Spring Boot • Create an Angular REST client and deploy it under Spring Boot • Demo of a sample Angular app that uses REST and WebSockets
  • 5. Angular Framework • Component-based (not MVC) • Dependency Injection • Router • Integrated RxJS • Can write apps in TypeScript, Dart, or JavaScript • UI components: Angular Material 2 • The rendering engine
  • 6. The landing page of an Auction app
  • 7. An app is a tree of components
  • 9. import {Component} from '@angular/core';
 import {Product, ProductService} from '../services/product-service';
 
 @Component({
 selector: 'app-root', 
 templateUrl: 'application.html',
 styleUrls: ['application.css']
 })
 export class AppComponent {
 products: Array<Product> = []; 
 
 constructor(private productService: ProductService) { 
 this.products = this.productService.getProducts(); 
 }
 } HTML, CSS TypeScript
  • 11. Arrow Function Expressions let getName = () => 'John Smith'; console.log(`The name is ` + getName()); Anonymous
 function
  • 12. A Class With Constructor TypeScript JavaScript (ES5)
  • 17. What’s Angular CLI • Scaffolding the project and creating a basic app • Generating components, services, modules, etc. • Serving the app to the browser • Bundling apps for dev and prod deployments • Generates boilerplate unit tests and configures test runners
  • 18. Demo - Generating a new project
 - Dev and prod builds with Angular CLI
  • 20. Router’s features - Pass data to routes - Child component can have their routes - Multiple router outlets - Guarding routes - Lazy loading of modules
  • 21. Dependency Injection • Angular injects values into components via constructors • Each component has its own injector • You specify a provider so Angular knows what to inject
  • 22. A sample injectable service @Injectable() export class ProductService{ 
 getProducts(): Product {
 // An HTTP request can go here 
 
 return new Product( 0, "iPhone 7", 249.99, "The latest iPhone, 7-inch screen");
 }
 }
  • 23. Injecting the ProductService import {Component} from ‘@angular/core';
 import {ProductService, Product} from “./product.service";
 
 @Component({
 selector: 'di-product-page',
 template: `<div>
 <h1>Product Details</h1>
 <h2>Title: {{product.title}}</h2>
 <h2>Description: {{product.description}}</h2>
 <h2>Price: ${{product.price}}</h2>
 </div>`,
 providers:[ProductService]
 })
 
 export class ProductComponent {
 product: Product;
 
 constructor( productService: ProductService ) {
 this.product = productService.getProduct();
 }
 } Injection
  • 24. Reactive Programming: Push Subscribe to messages from Observable and handle them by Observer Observer Subscriber Observer Subscriber push push push Observer Subscriber Observable Data
 Source
  • 25. Reactive programming in Angular - Router
 - Reactive Forms
 - EventEmitter (a subclass of Subject) - Handling HTTP responses
 - WebSockets
  • 26. Http and Observables 
 class AppComponent implements OnInit{
 
 products: Array = [];
 
 constructor(private http: Http) {} ngOnInit() {
 this.http.get(‘/api/products’)
 .map(res => res.json()) // Turn JSON from HTTP response into JS obj
 .subscribe(
 data => {
 
 this.products=data;
 },
 
 err =>
 console.log("Can't get products. Error code: %s, URL: %s ",
 err.status, err.url),
 
 () => console.log('Product(s) are retrieved')
 );
 }
 } O b s e r v e r
  • 28. @Input properties @Component({
 selector: 'order-processor',
 template: `...`
 }) class OrderComponent {
 
 @Input() quantity: number;
 
 @Input()
 set stockSymbol(value: string) {
 // process the stockSymbol change here
 }
 <order-processor [stockSymbol]="stock" quantity="100"></order-processor> Child Parent
  • 29. @Output properties class PriceQuoterComponent {
 
 @Output() lastPrice: EventEmitter <IPriceQuote> = new EventEmitter();
 
 stockSymbol: string = "IBM";
 
 constructor() {
 setInterval(() => {
 let priceQuote: IPriceQuote = {
 stockSymbol: this.stockSymbol,
 lastPrice: 100*Math.random()
 };
 
 this.lastPrice.emit(priceQuote);
 
 }, 1000);
 }
 } <price-quoter (lastPrice)="priceQuoteHandler($event)"></price-quoter><br> Child Parent
  • 30. An injectable service as a mediator
  • 31. Forms API - Template-driven forms - Reactive forms - Form validation
  • 32. A template-driven form @Component({
 selector: 'app-root',
 template: `
 <form #f="ngForm" (ngSubmit)="onSubmit(f.value)">
 <div>Username: <input type="text" name="username" ngModel></div>
 <div>SSN: <input type="text" name="ssn" ngModel></div>
 <div>Password: <input type="password" name="password" ngModel></div>
 <div>Confirm password: <input type="password" name="pconfirm" ngModel></div>
 <button type="submit">Submit</button>
 </form>
 `
 })
 export class AppComponent {
 onSubmit(formData) {
 console.log(formData);
 }
 }
  • 33. "scripts": {
 
 "start": "ng serve --proxy-config proxy.conf.json",
 
 "build": "ng build -prod",
 
 "postbuild": "npm run deploy”, 
 "predeploy": "rimraf ../server/build/public && mkdirp ../server/build/public”, 
 "deploy": "copyfiles -f dist/** ../server/build/public"
 } Automating deployments with npm scripts static
 resources
  • 34. Demo
 Angular + Spring Boot Java Angular
  • 35. Designed in 1995 in Norway (still alive)
  • 36. What’s Material Design? Material design is visual language (a spec) that defines the classic principles of good design.
  • 38. Angular Material 2 Need more components? Use the library PrimeNG
  • 39. Demo
  • 40. Thank you! • The book code samples:
 https://github.com/Farata/angular2typescript • Training inquiries: 
 training@faratasystems.com • My blog:
 yakovfain.com • Twitter: @yfain
 ctwdevoxxus
 40% off