SlideShare a Scribd company logo
Angular 4
Quick introduction for AngularJS 1.5 developers
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
Angular 4
Quick introduction for AngularJS 1.5 developers
a.k.a.
How to not write a large or scalable web applications.
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
Angular 4
Quick introduction for AngularJS 1.5 developers
a.k.a.
How to not write a large or scalable web applications.
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
Angular 4
Quick introduction for AngularJS 1.5 developers
a.k.a.
How to not write a large or scalable web applications.
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
Agenda
• @AboutMe()
• Javascript ecosystem (prepare the environment during this part)
• Trends
• Modules
• Javascript fatigue
• Workshop
• Boilerplate
• Blueprints
• Typescript/Angular
• Building blocks – service, component, dependency injection
• Q&A
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
@AboutMe()
• I started programming 18 years ago
• I code for money from the 9 years
• I code for Decerto 3 years
• I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript
• I did some AJAX before it was popular
• I did some UX before it was so popular
• I did some Devops before it was so named
• I was programming SPAs over the last 4 years in AngularJS
• I observe the development of Angular 2 since AngularJS 1.5-beta.0
• I am doing SPA in Angular 2 the last few months
• I switch to Angular 4 in the coming weeks
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
@AboutMe()
• I started programming 18 years ago
• I code for money from the 9 years
• I code for Decerto 3 years
• I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript
• I did some AJAX before it was popular
• I did some UX before it was so popular
• I did some Devops before it was so named
• I was programming SPAs over the last 4 years in AngularJS
• I observe the development of Angular 2 since AngularJS 1.5-beta.0
• I am doing SPA in Angular 2 the last few months
• I switch to Angular 4 in the coming weeks
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23
Workshop (It is the time to prepare environment)
• You should have installed:
• node >= 6.9.0 (https://nodejs.org/  download and install LTS)
• npm >= 3.0.0 (bundled with node)
• git
• bash (winbash, gitbash, zsh)
• typescript aware IDE
• Intellij Idea Ultimate / Intellij Idea Ultimate EAP
• Microsoft Visual Studio Code
• Microsoft Visual Studio
• Atom
• Your favorite
Task 0 – Hello world
Task 0 – Hello world
• npm install --global @angular/cli@latest # first time only
• ng new --ng4 my-project # first time only
# Let scripts do the work…
Trends
Trends trends
Trends trends trends
Trends trends trends trends
Trends trends trends trends trends
Trends trends trends trends trends trends
Trends…
• Trends proves (almost) every thesis
• angular and react in game
• It’s hard to say which is better
• Angularjs migrates to Angular
• Jquery still popular but it is going down
Task 0 – Hello world (remind)
• npm install --global @angular/cli@latest # first time only
• ng new --ng4 my-project # first time only
# Let scripts do the work…
There are frameworks
• Angular
• AngularJS
• Aurelia
• Backbone
• CycleJs
• Elm
• EmberJs
• ExtJs
• Knockout
• Meteor
• Mithril
• Polymer
• Preact
• React
• VueJs
There are packages managers
• Bower
• Npm
• (WebJars)
• Yarn
(modules without Javascript ecosystem)
(modules without Javascript ecosystem)
Task 0 – Hello world (remind)
• npm install --global @angular/cli@latest # first time only
• ng new --ng4 my-project # first time only
# Let scripts do the work…
There are languages
• ClojureScript
• CofeeScript
• Dart
• Ecmascript 5
• Ecmascript 2015
• Ecmasrcipt 2016
• Elm
• Typescript
There are compilers/transpilers
• Babel
• Clojure
• CoffeScript
• Dart
• Elm
• Emscripten
• Google Closure Compiler
• Typescript
There are static analyzis tools
• Codelyzer
• JSHint
• JSLint
• TSLint
There are template engines
• HandleBars
• Jade
• JSX
There are unit test frameworks
• Ava
• Chai
• Jasmine
• Mocha
• Qunit
• Sinon.js
• Wallaby*
There are styling languages/tools
• CSS
• compass
• Less
• PostCSS
• Sass
• Scss
• Stylus
There are boilerplate tools
• @angular/cli
• Seed projects
• yeoman
There are task runners
• (Gradle)
• Grunt
• Gulp
• (Maven)
• (Makefile)
• Npm
There are bundlers
• Brocholi
• Brunch
• Browserify
• Google Closure
• JSPM
• Rollup
• Webpack
• SystemJS
There are core JS Libraries
• Bacon
• Bluebird
• D3
• Hammerjs
• Jquery
• Lodash
• Lunr.js
• Modernizr
• Moment
• Rambda
• RxJs
• Three.js
• Underscore
• Zepto
There is Javascript Fatigue
https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f
Angular
• @angular/cli*
• CSS or SCSS – the only one true decision to make
• Codelyzer
• Jasmine
• Npm
• RxJs
• Webpack
• TSLint
• Typescript*
* You can replace, but you propably don’t want to
Workshop/Demo
• You should have installed:
• node >= 6.9.0 (https://nodejs.org/  download and install LTS)
• npm >= 3.0.0 (budled with node)
• git
• bash (winbash, gitbash, zsh)
• typescript aware IDE
• Intellij Idea Ultimate / Intellij Idea Ultimate EAP
• Microsoft Visual Studio Code
• Microsoft Visual Studio
• Atom
• Your favorite
Task 0 – Hello world (remind)
• npm install --global @angular/cli@latest # first time only
• ng new --ng4 my-project # first time only
Boilerplate, scripts, blueprints
• npm run build
• npm run test
• npm run lint
• npm run e2e
• npm run ng make-this-awesome
• npm run start -- --port 4444
• npm run ng -- generate <class | component | directive | enum |
guard | interface | module | pipe | service> [options] name
Typescript (open app.component.ts)
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app works!';
}
ES2015 import modules Exported symbol from module Module in node_modules
Decorator
(not an annotation!)
POJO
ES2015 export modules
Syntactic sugar for
Object with prototypal inharitance
String property on instance
Task 1 – Count to a random number
Task 1 – Count to a random number
AppComponent
CounterComponent
RandomNumberGeneratorService
Plain old button
Task 1 – Count to a random number
• Create counter component
• Create Random Number Generator Interface
• Define the inferface
• Create a RNG Service
• Implement counter
• Generate random number
• Handle click
Task 1 – create counter component
• npm run ng -- generate component --inline-style --inline-template
counter
Typescript (open counter.component.ts)
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-counter',
template: `
<p>
counter Works!
</p>
`,
styles: []
})
export class CounterComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Template string
Constructor
Method Interface
Task 1 – create interface
• npm run ng -- generate interface random-number-generator
Typescript (replace random-number-generator.ts)
export interface RandomNumberGenerator {
readonly name: string;
readonly infoUrl: string;
next (state: any): {state: any, value: number};
reset (seed?: any): any;
}
Readonly property… …of type string
Return type
OptionalMethod signature Value of any type
(Simpliest ever random number generator)
(Simpliest ever random number generator)
https://xkcd.com/221/
Task 1 – create service
• npm run ng -- generate service xkcd-rng
import {Injectable} from '@angular/core';
import {RandomNumberGenerator} from './random-number-generator';
@Injectable()
export class XkcdRngService implements RandomNumberGenerator {
readonly infoUrl = 'https://xkcd.com/221/';
readonly name = 'XKCD Random Number Generator';
reset() {
return null;
}
next(state: any = null) {
return {state, value: 4};
}
}
Typescript (replace xkcd-rng.service.ts)
Default value
Property shorthand
Task 1 – implement counter
Angular (replace counter.component.ts)
import {Component, Input, Output, EventEmitter} from '@angular/core';
@Component({
selector: 'app-counter',
template: `{{ tick | async }}`,
})
export class CounterComponent {
@Input() counter = 5;
@Input() delay = 90;
@Output() finish = new EventEmitter<boolean>();
@Output() tick = new EventEmitter<number>();
public start(): void {
this.count(0);
}
private count(n: number): void {
this.tick.emit(n);
if (n >= this.counter) {
this.finish.emit(true);
} else {
setTimeout(() => this.count(n + 1), this.delay);
}
}
}
How to not write a large or scalable web applications.
It will count to 5
unless you specify
otherwise
It will be placed in <app-counter> element
It will display current tick number whenever it comes
It’s a component
It will wait 90ms
between ticks
unless you specify
otherwise
It will tell you about finish
It will tell you about tick
You can start counting down
Look! There is no $apply!
Task 1 – generate random number
Angular (replace app.component.ts, add XkcdRngService in providers in AppModule)
import {Component, OnInit} from '@angular/core';
import {XkcdRngService} from './xkcd-rng.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
counter: number;
constructor(public xkcd: XkcdRngService) {
}
ngOnInit(): void {
this.counter = this.xkcd.next().value;
}
}
Dependency injection
Assigned to component
if public/private specified
Lifecycle hook
providers: [
XkcdRngService,
],
Task 1 – handle click
Angular (replace app.component.{html,css}
<section>
<button (click)="cnt.start()">Start</button>
<h2>
<app-counter #cnt
[counter]="counter"></app-counter>
</h2>
</section>
h2 {
display: inline-block;
margin: 0;
}
button {
margin: 10px;
padding: 10px;
}
Input in app-counter Property from app-root
Handle output
Local template variable
- definition and usage
Access target component API
Task 2 – Multiple count to a random numbers
Task 2 – Multiple count to a random numbers
Task 1
RNG name and link
Random
independent
counters
Configurable
Task 2 – Multiple count to a random numbers
• Create another RNG service (this time configurable)
• Multiple counters
• Inject service
• Make service injection configurable which depends on environment
Task 2 – Create another RNG service
• npm run ng -- generate service lcg-rng-factory
Typescript / Angular (replace lcg-rng-factory.service.ts)
import {Injectable} from '@angular/core';
import {RandomNumberGenerator} from './random-number-generator';
interface LcgState { prev: number; multiplier: number; increment: number; modulo: number; }
const LCG_INFO_URL = 'https://en.wikipedia.org/wiki/Linear_congruential_generator';
@Injectable()
export class LcgRngFactoryService {
private createLcg(name: string, initialState: LcgState): RandomNumberGenerator {
return { infoUrl: LCG_INFO_URL, name,
reset: (seed = 1) => Object.assign({}, initialState, {prev: seed}),
next: (state: LcgState = initialState) => {
const prev = (state.multiplier * state.prev + state.increment) % state.modulo;
return {value: prev, state: Object.assign({}, state, {prev})};
}
};
}
public glibc() { return this.createLcg('glibc', {prev: 1, multiplier: 1103515245, increment: 12345, modulo: 2 ** 31 - 1}); }
public random0(){ return this.createLcg('random0', {prev: 1, multiplier: 8121, increment: 28411, modulo: 134456}); }
public minstd(){ return this.createLcg('minstd_rand', {prev: 1, multiplier: 48271, increment: 0, modulo: 2 ** 31 - 1}); }
}
Local
interface
Local
constant
Block
scope
variable Fat arrow function ("fart") – function without this
Angular (replace app.component.html)
<h1>RNG: <a [href]="rng.infoUrl">{{ rng.name }}</a></h1>
<section *ngFor="let counter of numbers">
<button (click)="cnt.start()">Start</button>
<h2>
<app-counter #cnt
[counter]="counter"></app-counter>
</h2>
</section>
ng-repeat replacement
Local variable
No changes here
Task 2 – Injectable RNG service
Angular – DI (replace app.component.ts body)
public numbers: number[];
private rngState: any;
constructor(public xkcd: XkcdRngService, @Inject('RNG') public rng: RandomNumberGenerator) { }
ngOnInit(): void {
this.rngState = this.rng.reset();
const length = 1 + this.xkcd.next().value % 10;
this.numbers = Array.from({length}).map(() => this.random());
}
private random(n = 50): number {
const {state, value} = this.rng.next(this.rngState);
this.rngState = state;
return value % n;
}
DI symbol
How to not write a large or scalable web applications.
export function rngFactory(lcg: LcgRngFactoryService, x: XkcdRngService){
if(environment.production){
return lcg.glibc();
}else{
return x;
}
}
@NgModule({
// ...
providers: [
XkcdRngService,
LcgRngFactoryService,
// {provide: 'RNG', useClass: XkcdRngService},
{provide: 'RNG', useFactory: rngFactory, deps: [LcgRngFactoryService, XkcdRngService]},
],
// ...
})
export class AppModule { }
Angular – DI (replace app.module.ts providers)
DI symbol
Comes from src/enviroments/*.ts
Serve in two variants of the enviroment
• npm run start -- --port 4444
• npm run start -- --port 4444 -e prod
Q&A
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-03-23

More Related Content

PPTX
An Overview of Angular 4
Cynoteck Technology Solutions Private Limited
 
PDF
Angular 2 Essential Training
Patrick Schroeder
 
PDF
Introduction to Angular 2
Naveen Pete
 
PDF
Introduction to angular 4
Marwane El Azami
 
PPTX
Introduction to angular 2
Dor Moshe
 
PPTX
Angular 2
Travis van der Font
 
PDF
What is Angular version 4?
Troy Miles
 
PDF
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 
Angular 2 Essential Training
Patrick Schroeder
 
Introduction to Angular 2
Naveen Pete
 
Introduction to angular 4
Marwane El Azami
 
Introduction to angular 2
Dor Moshe
 
What is Angular version 4?
Troy Miles
 
Tech Webinar: Angular 2, Introduction to a new framework
Codemotion
 

What's hot (20)

ODP
Introduction to Angular 2
Knoldus Inc.
 
PDF
Angular 2 - The Next Framework
Commit University
 
PDF
Introduction to angular 2
Dhyego Fernando
 
PDF
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
PPSX
Angular 4 fronts
badal dubla
 
PDF
Exploring Angular 2 - Episode 1
Ahmed Moawad
 
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
PDF
An Intro to Angular 2
Ron Heft
 
PDF
Angular 2 for Java Developers
Yakov Fain
 
PPTX
Angular 4 - quick view
Michael Haberman
 
PDF
Angular 2... so can I use it now??
Laurent Duveau
 
PDF
Angular2 with TypeScript
Rohit Bishnoi
 
PPTX
Angular4 getting started
TejinderMakkar
 
PDF
Angular 2: What's New?
jbandi
 
PDF
Exploring Angular 2 - Episode 2
Ahmed Moawad
 
PPTX
Angular 4 Introduction Tutorial
Scott Lee
 
ODP
Angular 6 - The Complete Guide
Sam Dias
 
PDF
Angular 2: core concepts
Codemotion
 
PDF
Angular 2 - Core Concepts
Fabio Biondi
 
PDF
Express: A Jump-Start
Naveen Pete
 
Introduction to Angular 2
Knoldus Inc.
 
Angular 2 - The Next Framework
Commit University
 
Introduction to angular 2
Dhyego Fernando
 
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
Angular 4 fronts
badal dubla
 
Exploring Angular 2 - Episode 1
Ahmed Moawad
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Codemotion
 
An Intro to Angular 2
Ron Heft
 
Angular 2 for Java Developers
Yakov Fain
 
Angular 4 - quick view
Michael Haberman
 
Angular 2... so can I use it now??
Laurent Duveau
 
Angular2 with TypeScript
Rohit Bishnoi
 
Angular4 getting started
TejinderMakkar
 
Angular 2: What's New?
jbandi
 
Exploring Angular 2 - Episode 2
Ahmed Moawad
 
Angular 4 Introduction Tutorial
Scott Lee
 
Angular 6 - The Complete Guide
Sam Dias
 
Angular 2: core concepts
Codemotion
 
Angular 2 - Core Concepts
Fabio Biondi
 
Express: A Jump-Start
Naveen Pete
 
Ad

Viewers also liked (20)

PDF
Architektura ngrx w angular 2+
Paweł Żurowski
 
PPTX
Dive into Angular, part 4: Angular 2.0
Oleksii Prohonnyi
 
PDF
Angular 4 for Java Developers
Yakov Fain
 
PDF
Getting Started with Angular 2
FITC
 
PDF
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
PDF
Building Universal Applications with Angular 2
Minko Gechev
 
PPTX
Hello AngularJS - Back to the future
Ouadie LAHDIOUI
 
PPTX
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
PDF
Introduction to ReactJS
Tu Hoang
 
PDF
Workshop 22: ReactJS Redux Advanced
Visual Engineering
 
PDF
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
PPT
TypeScript Presentation
Patrick John Pacaña
 
PDF
panduan-google-adsense.pdf
SMK Negeri 6 Malang
 
PPTX
Angular 2 Migration - JHipster Meetup 6
William Marques
 
PDF
React 101
Casear Chu
 
PPTX
004. Working with React component
Binh Quan Duc
 
PPT
Starting with Reactjs
Thinh VoXuan
 
PPTX
002. Working with Webpack
Binh Quan Duc
 
PPTX
001. Introduction about React
Binh Quan Duc
 
PDF
Exploiting Deserialization Vulnerabilities in Java
CODE WHITE GmbH
 
Architektura ngrx w angular 2+
Paweł Żurowski
 
Dive into Angular, part 4: Angular 2.0
Oleksii Prohonnyi
 
Angular 4 for Java Developers
Yakov Fain
 
Getting Started with Angular 2
FITC
 
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Building Universal Applications with Angular 2
Minko Gechev
 
Hello AngularJS - Back to the future
Ouadie LAHDIOUI
 
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
Introduction to ReactJS
Tu Hoang
 
Workshop 22: ReactJS Redux Advanced
Visual Engineering
 
Angular (v2 and up) - Morning to understand - Linagora
LINAGORA
 
TypeScript Presentation
Patrick John Pacaña
 
panduan-google-adsense.pdf
SMK Negeri 6 Malang
 
Angular 2 Migration - JHipster Meetup 6
William Marques
 
React 101
Casear Chu
 
004. Working with React component
Binh Quan Duc
 
Starting with Reactjs
Thinh VoXuan
 
002. Working with Webpack
Binh Quan Duc
 
001. Introduction about React
Binh Quan Duc
 
Exploiting Deserialization Vulnerabilities in Java
CODE WHITE GmbH
 
Ad

Similar to Quick introduction to Angular 4 for AngularJS 1.5 developers (20)

PDF
Architecture for scalable Angular applications (with introduction and extende...
Paweł Żurowski
 
PDF
The 4W's of Angular
Lena Lekkou
 
PPTX
Angular 2 On Production (IT Talk in Dnipro)
Oleksandr Tryshchenko
 
PDF
Angular Weekend
Troy Miles
 
PDF
Angular Meetup 1 - Angular Basics and Workshop
Nitin Bhojwani
 
PDF
Myths of Angular 2: What Angular Really Is
DevFest DC
 
PPTX
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
PDF
Migrating to Angular 4 for Spring Developers
VMware Tanzu
 
PDF
Angular js
Felixits
 
PDF
Angular js
Felixits
 
PDF
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
PDF
From MEAN to the MERN Stack
Troy Miles
 
PDF
Angular 2 overview
Jesse Warden
 
PPTX
Angular2
Oswald Campesato
 
PPTX
Web technologies-course 12.pptx
Stefan Oprea
 
PPTX
Angular
khoado2002
 
PDF
Angular, the New Angular JS
Kenzan
 
PDF
MEAN Stack Warm-up
Troy Miles
 
PDF
Angular JS2 Training Session #1
Paras Mendiratta
 
PDF
Brief introduction to Angular 2.0 & 4.0
Nisheed Jagadish
 
Architecture for scalable Angular applications (with introduction and extende...
Paweł Żurowski
 
The 4W's of Angular
Lena Lekkou
 
Angular 2 On Production (IT Talk in Dnipro)
Oleksandr Tryshchenko
 
Angular Weekend
Troy Miles
 
Angular Meetup 1 - Angular Basics and Workshop
Nitin Bhojwani
 
Myths of Angular 2: What Angular Really Is
DevFest DC
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Migrating to Angular 4 for Spring Developers
VMware Tanzu
 
Angular js
Felixits
 
Angular js
Felixits
 
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
From MEAN to the MERN Stack
Troy Miles
 
Angular 2 overview
Jesse Warden
 
Web technologies-course 12.pptx
Stefan Oprea
 
Angular
khoado2002
 
Angular, the New Angular JS
Kenzan
 
MEAN Stack Warm-up
Troy Miles
 
Angular JS2 Training Session #1
Paras Mendiratta
 
Brief introduction to Angular 2.0 & 4.0
Nisheed Jagadish
 

Recently uploaded (20)

PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PDF
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
PPTX
introduction to dart --- Section one .pptx
marknaiem92
 
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PDF
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
PPT
Overview of Oracle Receivables Process.ppt
nbvreddy229
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
introduction to dart --- Section one .pptx
marknaiem92
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
Overview of Oracle Receivables Process.ppt
nbvreddy229
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Exploring AI Agents in Process Industries
amoreira6
 

Quick introduction to Angular 4 for AngularJS 1.5 developers

  • 1. Angular 4 Quick introduction for AngularJS 1.5 developers Paweł Żurowski <[email protected]> 2017-03-23
  • 2. Angular 4 Quick introduction for AngularJS 1.5 developers a.k.a. How to not write a large or scalable web applications. Paweł Żurowski <[email protected]> 2017-03-23
  • 3. Angular 4 Quick introduction for AngularJS 1.5 developers a.k.a. How to not write a large or scalable web applications. Paweł Żurowski <[email protected]> 2017-03-23
  • 4. Angular 4 Quick introduction for AngularJS 1.5 developers a.k.a. How to not write a large or scalable web applications. Paweł Żurowski <[email protected]> 2017-03-23
  • 5. Agenda • @AboutMe() • Javascript ecosystem (prepare the environment during this part) • Trends • Modules • Javascript fatigue • Workshop • Boilerplate • Blueprints • Typescript/Angular • Building blocks – service, component, dependency injection • Q&A Paweł Żurowski <[email protected]> 2017-03-23
  • 6. @AboutMe() • I started programming 18 years ago • I code for money from the 9 years • I code for Decerto 3 years • I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript • I did some AJAX before it was popular • I did some UX before it was so popular • I did some Devops before it was so named • I was programming SPAs over the last 4 years in AngularJS • I observe the development of Angular 2 since AngularJS 1.5-beta.0 • I am doing SPA in Angular 2 the last few months • I switch to Angular 4 in the coming weeks Paweł Żurowski <[email protected]> 2017-03-23
  • 7. @AboutMe() • I started programming 18 years ago • I code for money from the 9 years • I code for Decerto 3 years • I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript • I did some AJAX before it was popular • I did some UX before it was so popular • I did some Devops before it was so named • I was programming SPAs over the last 4 years in AngularJS • I observe the development of Angular 2 since AngularJS 1.5-beta.0 • I am doing SPA in Angular 2 the last few months • I switch to Angular 4 in the coming weeks Paweł Żurowski <[email protected]> 2017-03-23
  • 8. Workshop (It is the time to prepare environment) • You should have installed: • node >= 6.9.0 (https://nodejs.org/  download and install LTS) • npm >= 3.0.0 (bundled with node) • git • bash (winbash, gitbash, zsh) • typescript aware IDE • Intellij Idea Ultimate / Intellij Idea Ultimate EAP • Microsoft Visual Studio Code • Microsoft Visual Studio • Atom • Your favorite
  • 9. Task 0 – Hello world
  • 10. Task 0 – Hello world • npm install --global @angular/cli@latest # first time only • ng new --ng4 my-project # first time only # Let scripts do the work…
  • 15. Trends trends trends trends trends
  • 16. Trends trends trends trends trends trends
  • 17. Trends… • Trends proves (almost) every thesis • angular and react in game • It’s hard to say which is better • Angularjs migrates to Angular • Jquery still popular but it is going down
  • 18. Task 0 – Hello world (remind) • npm install --global @angular/cli@latest # first time only • ng new --ng4 my-project # first time only # Let scripts do the work…
  • 19. There are frameworks • Angular • AngularJS • Aurelia • Backbone • CycleJs • Elm • EmberJs • ExtJs • Knockout • Meteor • Mithril • Polymer • Preact • React • VueJs
  • 20. There are packages managers • Bower • Npm • (WebJars) • Yarn
  • 23. Task 0 – Hello world (remind) • npm install --global @angular/cli@latest # first time only • ng new --ng4 my-project # first time only # Let scripts do the work…
  • 24. There are languages • ClojureScript • CofeeScript • Dart • Ecmascript 5 • Ecmascript 2015 • Ecmasrcipt 2016 • Elm • Typescript
  • 25. There are compilers/transpilers • Babel • Clojure • CoffeScript • Dart • Elm • Emscripten • Google Closure Compiler • Typescript
  • 26. There are static analyzis tools • Codelyzer • JSHint • JSLint • TSLint
  • 27. There are template engines • HandleBars • Jade • JSX
  • 28. There are unit test frameworks • Ava • Chai • Jasmine • Mocha • Qunit • Sinon.js • Wallaby*
  • 29. There are styling languages/tools • CSS • compass • Less • PostCSS • Sass • Scss • Stylus
  • 30. There are boilerplate tools • @angular/cli • Seed projects • yeoman
  • 31. There are task runners • (Gradle) • Grunt • Gulp • (Maven) • (Makefile) • Npm
  • 32. There are bundlers • Brocholi • Brunch • Browserify • Google Closure • JSPM • Rollup • Webpack • SystemJS
  • 33. There are core JS Libraries • Bacon • Bluebird • D3 • Hammerjs • Jquery • Lodash • Lunr.js • Modernizr • Moment • Rambda • RxJs • Three.js • Underscore • Zepto
  • 34. There is Javascript Fatigue https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f
  • 35. Angular • @angular/cli* • CSS or SCSS – the only one true decision to make • Codelyzer • Jasmine • Npm • RxJs • Webpack • TSLint • Typescript* * You can replace, but you propably don’t want to
  • 36. Workshop/Demo • You should have installed: • node >= 6.9.0 (https://nodejs.org/  download and install LTS) • npm >= 3.0.0 (budled with node) • git • bash (winbash, gitbash, zsh) • typescript aware IDE • Intellij Idea Ultimate / Intellij Idea Ultimate EAP • Microsoft Visual Studio Code • Microsoft Visual Studio • Atom • Your favorite
  • 37. Task 0 – Hello world (remind) • npm install --global @angular/cli@latest # first time only • ng new --ng4 my-project # first time only
  • 38. Boilerplate, scripts, blueprints • npm run build • npm run test • npm run lint • npm run e2e • npm run ng make-this-awesome • npm run start -- --port 4444 • npm run ng -- generate <class | component | directive | enum | guard | interface | module | pipe | service> [options] name
  • 39. Typescript (open app.component.ts) import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { title = 'app works!'; } ES2015 import modules Exported symbol from module Module in node_modules Decorator (not an annotation!) POJO ES2015 export modules Syntactic sugar for Object with prototypal inharitance String property on instance
  • 40. Task 1 – Count to a random number
  • 41. Task 1 – Count to a random number AppComponent CounterComponent RandomNumberGeneratorService Plain old button
  • 42. Task 1 – Count to a random number • Create counter component • Create Random Number Generator Interface • Define the inferface • Create a RNG Service • Implement counter • Generate random number • Handle click
  • 43. Task 1 – create counter component • npm run ng -- generate component --inline-style --inline-template counter
  • 44. Typescript (open counter.component.ts) import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-counter', template: ` <p> counter Works! </p> `, styles: [] }) export class CounterComponent implements OnInit { constructor() { } ngOnInit() { } } Template string Constructor Method Interface
  • 45. Task 1 – create interface • npm run ng -- generate interface random-number-generator
  • 46. Typescript (replace random-number-generator.ts) export interface RandomNumberGenerator { readonly name: string; readonly infoUrl: string; next (state: any): {state: any, value: number}; reset (seed?: any): any; } Readonly property… …of type string Return type OptionalMethod signature Value of any type
  • 47. (Simpliest ever random number generator)
  • 48. (Simpliest ever random number generator) https://xkcd.com/221/
  • 49. Task 1 – create service • npm run ng -- generate service xkcd-rng
  • 50. import {Injectable} from '@angular/core'; import {RandomNumberGenerator} from './random-number-generator'; @Injectable() export class XkcdRngService implements RandomNumberGenerator { readonly infoUrl = 'https://xkcd.com/221/'; readonly name = 'XKCD Random Number Generator'; reset() { return null; } next(state: any = null) { return {state, value: 4}; } } Typescript (replace xkcd-rng.service.ts) Default value Property shorthand
  • 51. Task 1 – implement counter
  • 52. Angular (replace counter.component.ts) import {Component, Input, Output, EventEmitter} from '@angular/core'; @Component({ selector: 'app-counter', template: `{{ tick | async }}`, }) export class CounterComponent { @Input() counter = 5; @Input() delay = 90; @Output() finish = new EventEmitter<boolean>(); @Output() tick = new EventEmitter<number>(); public start(): void { this.count(0); } private count(n: number): void { this.tick.emit(n); if (n >= this.counter) { this.finish.emit(true); } else { setTimeout(() => this.count(n + 1), this.delay); } } } How to not write a large or scalable web applications. It will count to 5 unless you specify otherwise It will be placed in <app-counter> element It will display current tick number whenever it comes It’s a component It will wait 90ms between ticks unless you specify otherwise It will tell you about finish It will tell you about tick You can start counting down Look! There is no $apply!
  • 53. Task 1 – generate random number
  • 54. Angular (replace app.component.ts, add XkcdRngService in providers in AppModule) import {Component, OnInit} from '@angular/core'; import {XkcdRngService} from './xkcd-rng.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { counter: number; constructor(public xkcd: XkcdRngService) { } ngOnInit(): void { this.counter = this.xkcd.next().value; } } Dependency injection Assigned to component if public/private specified Lifecycle hook providers: [ XkcdRngService, ],
  • 55. Task 1 – handle click
  • 56. Angular (replace app.component.{html,css} <section> <button (click)="cnt.start()">Start</button> <h2> <app-counter #cnt [counter]="counter"></app-counter> </h2> </section> h2 { display: inline-block; margin: 0; } button { margin: 10px; padding: 10px; } Input in app-counter Property from app-root Handle output Local template variable - definition and usage Access target component API
  • 57. Task 2 – Multiple count to a random numbers
  • 58. Task 2 – Multiple count to a random numbers Task 1 RNG name and link Random independent counters Configurable
  • 59. Task 2 – Multiple count to a random numbers • Create another RNG service (this time configurable) • Multiple counters • Inject service • Make service injection configurable which depends on environment
  • 60. Task 2 – Create another RNG service • npm run ng -- generate service lcg-rng-factory
  • 61. Typescript / Angular (replace lcg-rng-factory.service.ts) import {Injectable} from '@angular/core'; import {RandomNumberGenerator} from './random-number-generator'; interface LcgState { prev: number; multiplier: number; increment: number; modulo: number; } const LCG_INFO_URL = 'https://en.wikipedia.org/wiki/Linear_congruential_generator'; @Injectable() export class LcgRngFactoryService { private createLcg(name: string, initialState: LcgState): RandomNumberGenerator { return { infoUrl: LCG_INFO_URL, name, reset: (seed = 1) => Object.assign({}, initialState, {prev: seed}), next: (state: LcgState = initialState) => { const prev = (state.multiplier * state.prev + state.increment) % state.modulo; return {value: prev, state: Object.assign({}, state, {prev})}; } }; } public glibc() { return this.createLcg('glibc', {prev: 1, multiplier: 1103515245, increment: 12345, modulo: 2 ** 31 - 1}); } public random0(){ return this.createLcg('random0', {prev: 1, multiplier: 8121, increment: 28411, modulo: 134456}); } public minstd(){ return this.createLcg('minstd_rand', {prev: 1, multiplier: 48271, increment: 0, modulo: 2 ** 31 - 1}); } } Local interface Local constant Block scope variable Fat arrow function ("fart") – function without this
  • 62. Angular (replace app.component.html) <h1>RNG: <a [href]="rng.infoUrl">{{ rng.name }}</a></h1> <section *ngFor="let counter of numbers"> <button (click)="cnt.start()">Start</button> <h2> <app-counter #cnt [counter]="counter"></app-counter> </h2> </section> ng-repeat replacement Local variable No changes here
  • 63. Task 2 – Injectable RNG service
  • 64. Angular – DI (replace app.component.ts body) public numbers: number[]; private rngState: any; constructor(public xkcd: XkcdRngService, @Inject('RNG') public rng: RandomNumberGenerator) { } ngOnInit(): void { this.rngState = this.rng.reset(); const length = 1 + this.xkcd.next().value % 10; this.numbers = Array.from({length}).map(() => this.random()); } private random(n = 50): number { const {state, value} = this.rng.next(this.rngState); this.rngState = state; return value % n; } DI symbol How to not write a large or scalable web applications.
  • 65. export function rngFactory(lcg: LcgRngFactoryService, x: XkcdRngService){ if(environment.production){ return lcg.glibc(); }else{ return x; } } @NgModule({ // ... providers: [ XkcdRngService, LcgRngFactoryService, // {provide: 'RNG', useClass: XkcdRngService}, {provide: 'RNG', useFactory: rngFactory, deps: [LcgRngFactoryService, XkcdRngService]}, ], // ... }) export class AppModule { } Angular – DI (replace app.module.ts providers) DI symbol Comes from src/enviroments/*.ts
  • 66. Serve in two variants of the enviroment • npm run start -- --port 4444 • npm run start -- --port 4444 -e prod