SlideShare a Scribd company logo
1 of 59
Download to read offline
THE ANGULAR2
WORKSHOP
Nir Kaufman
Build Your First Angular2 Application
Nir Kaufman
- Wrote a book about Angular2
- Play the Bass
- Eat vegan food
Head of AngularJS Development @ 500Tech
AGENDA
GET A FEEL OF ANGULAR2
Understand Angular2 concepts
Get your hands on
Get a project that you can keep learning with
https://github.com/nirkaufman/
angular2-workshop.git
LET’S BUILD AN APP
TABLES DASHBOARD
ORDER EDITOR
ORDER HISTORY
PART 1
COMPONENTS
git checkout master
AN ANGULAR2 APPLICATION UI
IS A COMPOSITION OF COMPONENTS
(reusable UI building blocks)
THINKING IN COMPONENTS
APP
CONTENT
TABLES
TOP-NAVBAR
THIMKING IN COMPONENTS
TABLE-VIEW
THIMKING IN COMPONENTS
APP
TOP-NAVBAR CONTENT
TABLES
TABLE-VIEWTABLE-VIEWTABLE-VIEW
wrapper component
MOST BASIC COMPONENT
import { Component } from 'angular2/core';
@Component({

selector: 'App',

template: ‘<h1>Hello Component!</h1>’

})



class App {}
In JavaScript
Use in HTML
<body>



<App></App>



</body>
INSTRUCTIONS
copy the images folder from ‘_template’ to ‘ src/assets’
copy and paste custom css to ‘src/assets/css/app.css’
locate the ‘tables.html’ template inside the ‘_templates’ folder
create basic components, one per file, with a selector that
mach the component name and the corresponding template
HANDS ON - ON YOUR OWN!
Build our top level component tree for
our restaurant application.
git checkout 01_components
COMPONENT COMPOSITION
import {Component} from 'angular2/core';

import {TopNavBar} from './top-navbar';

import {Content} from './content';



@Component({

selector: 'app',

directives: [Content, TopNavBar],

template: `

<top-navbar></top-navbar>

<content></content>

`

})



export class App {}
import {Component} from "angular2/core";



@Component({

selector:'content',

template:`<div class="container"></div>`

})



export class Content {}
content.ts
app.ts
INSTRUCTIONS
separate the angular bootstrap to it’s own file
compose the components starting from the top app
component
review our application
HANDS ON - ALL TOGETHER!
Compose our component tree to build
our first ‘screen’
git checkout 02_composition
EXTENDING OUR COMPONENTS TREE
EXTENDING OUR COMPONENTS TREE
ORDER-VIEW-
FORM
NEW-ITEM-FORM ITEM-LIST ITEM-COMMENTS ITEM-BUTTONS
On a real application, we will
probably break this form to much
more smaller components
APP
TOP-NAVBAR CONTENT
TABLES
TABLE-
VIEW
TABLE-
VIEW
TABLE-
VIEW
wrapper component
ORDER-VIEW-
FORM
NEW-ITEM-FORM ITEM-LIST ITEM-COMMENTS ITEM-BUTTONS
ORDER-HISTORY
EXTENDING OUR COMPONENTS TREE
INSTRUCTIONS
checkout the 03_adding_components branch
find the templates on ‘_template’ folder (already extracted)
like before, keep each component on it’s on file
you can group components sub-trees in folders
HANDS ON - ON YOUR OWN!
code the missing components, test them by putting
them inside the content component
git checkout 04_all_components
PART 2
COMPONENT ROUTER
IN ANGULAR2 WE GOT A BRAND
NEW COMPONENT ROUTER
BASIC ROUTING IN 4 STEPS
set the <base href=“/"> tag
use the RouterConfig on the root component
use the RouterOutlet component as placeholder
use the RouterLink directive for links
THE ROUTER CONFIG


@RouteConfig([

{path: '/', name: 'root', redirectTo: ['Tables']},

{path:'/tables', name: 'Tables', component: Tables},

{path:’/order/:id',name: 'OrderView', component: OrderView},

{path:'/history', name: 'OrderHistory', component: OrderHistory}

])



@Component({

template: `

<top-navbar></top-navbar>



<div class="container">

<router-outlet></router-outlet>

</div>

`

})

app.ts
ROUTER LINKS
<ul class="nav navbar-nav">

<li><a [routerLink]="['/Tables']">tables</a></li>

<li><a [routerLink]="['/OrderHistory']">tables</a></li>

</ul>
INSTRUCTIONS
inject the ROUTER_PROVIDERS on application boot
config the routs on the top-level app component and replace
the content component with router-layout
add router links to the top-navbar component
HANDS ON - ALL TOGETHER!
Define basic routes to our application to navigate
through the tables and the history view
git checkout 05_routing
WE NEED TO PASS THE TABLE ID AS A
PARAMETER WHEN NAVIGATING TO
THE ORDER-FORM
WORKING WITH PARAMS
export class TableView {



constructor(private router:Router) {}



editOrder(){

this.router.navigate( ['OrderView', { id: 5 }] );

}

}
table-view.ts
export class OrderView {



constructor(private routeParams:RouteParams) {}



ngOnInit() {

let tableId = this.routeParams.get('id');

}

}
table-view.ts
INSTRUCTIONS
implement an ‘editOrder’ method on table-view component
that uses the Router to navigate to the order-view with an id.
extract the id param in the order-view component on the init
phase and log it to the console
HANDS ON - ALL TOGETHER!
Route to the order-view component with an id
param and pull this param on the view-order
component.
git checkout 06_route_params
PART 3
BUSINESS LOGIC
DATA MODELS
import {Item} from './item'



export class Order {



private orderId: string;

public created: Date;

public diners: number;

public items: Item[];

private comments: string;

private total: number;

public paid: boolean;

private closed: Date;



public constructor(diners: number = 1) {

this.orderId = Order.nextId();

this.created = new Date();

this.diners = diners;

this.paid = false;

this.total = 0;

}

Let’s build the order and the item interfaces in a folder named ‘types’
THE RESTAURANT MANAGER
Our restaurant logic needs a home. create a ‘services’ folder for it.
import {Order} from "./order";

import {Injectable} from "angular2/core";

import {Router} from "angular2/router";



export class Restaurant {



private _orders;



public constructor(private router:Router) {

this._orders = mockOrders;

}



public get orders(){

return this._orders;

}



public newOrder() {

let _order = new Order(1);

this._orders.push(_order);

this.router.navigate( ['OrderView', { id: _order.id }] );

}



public getOrderById(orderId) {

return this._orders.filter( order => order.id === orderId)[0];

}



public checkout(orderId){

this._orders.find(order => order.id === orderId).checkout()

}

}

DEPENDENCY INJECTION 101
In angular2 each component get it’s own Injector. The location of injection is important.
APP
TOP-NAVBAR CONTENT
TABLES
TABLE-VIEWTABLE-VIEWTABLE-VIEW
Service
Service
git checkout 07_business_logic
INSTRUCTIONS
make the business logic classes injectable extract the id
Inject the restaurant class to the app component (application
toot)
use some core directives for binding data to our components
cleanups and refactoring
HANDS ON - ALL TOGETHER!
Wire up our business logic to our components
and use some core directives
INSTRUCTIONS
use the familiar angular curly braces syntax
use the data pipe for formatting the date
implement the ‘checkout’ method on order view. remove it
from table-view
HANDS ON - ON YOUR OWN!
Bind the order object to the table-view
component.
git checkout 08_wiring
PIPES
Now, we like to filter our orders, and display just the ‘open’ tables on the dashboard.
In angular2 we got Pipes. A class that implement a transform method,
decorated with the @Pipe decorator.
import {Order} from "../services/order";

import {Pipe} from 'angular2/core';



@Pipe({

name: 'orderPipe'

})



export class OrderPipe {



transform(orders) {

return orders.filter( order => order.paid == false);

}

}

INSTRUCTIONS
create a ‘pipes’ directory
create a file named ‘orderPipe’
implement the transform method to return only the orders
that makes as open (paid = false)
decorate with a @Pipe and declare it on the tables component
HANDS ON - ALL TOGETHER!
Let’s create a pipe for filtering the tables showing
only the orders that that opened.
git checkout 09_pipe
COLLECTION USER DATA
INSTRUCTIONS
bind the order id and diners count to the order view
build a select box using ngFor
get a reference to the ngForm and implement ngSubmit
use ng-control to bind the selected value to the order
HANDS ON - ALL TOGETHER!
Let’s bind data and make our order form to work by
using some core directives and Form directives
git checkout
10_collecting_user_data
INSTRUCTIONS
pass the order to the item-list
use the data pipe for formatting the date
implement the ‘checkout’ method on order view. remove it
from table-view
add comments to order
HANDS ON - ON YOUR OWN!
Make the items list to work! show items and
remove items. bonus: add comments.
git checkout 11_item_list
TALKING WITH SERVERS
The Http module was re-written in angular2. while it’s favourite reactive
programming b by depending on Rxjs, we can use it anyway we like.
git checkout 12_server
INSTRUCTIONS
use HTTP PROVIDERS
implement a get method to pull orders data
implement a post method to save orders to the database
bonus: create a dedicated service for http calls
HANDS ON - ALL TOGETHER!
Let’s bring orders data from the server.
git checkout 13_basic_http

More Related Content

What's hot

Peggy angular 2 in meteor
Peggy   angular 2 in meteorPeggy   angular 2 in meteor
Peggy angular 2 in meteorLearningTech
 
Angular js 2
Angular js 2Angular js 2
Angular js 2Ran Wahle
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next FrameworkCommit University
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Ross Dederer
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2Ivan Matiishyn
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core conceptsCodemotion
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Naveen Pete
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Minko Gechev
 
2 years of angular: lessons learned
2 years of angular: lessons learned2 years of angular: lessons learned
2 years of angular: lessons learnedDirk Luijk
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Codemotion
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascriptRan Wahle
 
Migrating to Angular 2
Migrating to Angular 2Migrating to Angular 2
Migrating to Angular 2FITC
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash CourseElisha Kramer
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!Nir Kaufman
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Ahmed Moawad
 

What's hot (20)

Peggy angular 2 in meteor
Peggy   angular 2 in meteorPeggy   angular 2 in meteor
Peggy angular 2 in meteor
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
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
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2
 
2 years of angular: lessons learned
2 years of angular: lessons learned2 years of angular: lessons learned
2 years of angular: lessons learned
 
AngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLIAngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLI
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
Migrating to Angular 2
Migrating to Angular 2Migrating to Angular 2
Migrating to Angular 2
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angular2
Angular2Angular2
Angular2
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
Angular 5
Angular 5Angular 5
Angular 5
 

Viewers also liked

Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready Nir Kaufman
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2Dragos Ionita
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2FITC
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core ConceptsFabio Biondi
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type scriptRavi Mone
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes WorkshopNir Kaufman
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Nir Kaufman
 
Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2thgreasi
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015Nir Kaufman
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and runningNir Kaufman
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6Nir Kaufman
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Dawid Myslak
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Nir Kaufman
 

Viewers also liked (20)

Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Angular2
Angular2Angular2
Angular2
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016
 
Angular 2
Angular 2Angular 2
Angular 2
 
Angular 2 - Better or worse
Angular 2 - Better or worseAngular 2 - Better or worse
Angular 2 - Better or worse
 
Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and running
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
 
Solid angular
Solid angularSolid angular
Solid angular
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Webstorm
WebstormWebstorm
Webstorm
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 

Similar to Angular2 workshop

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.AngularEvan Schultz
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2Paras Mendiratta
 
ngNewRouter
ngNewRouterngNewRouter
ngNewRouterphidong
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Ontico
 
angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfNuttavutThongjor1
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2Demey Emmanuel
 
Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburgBaqend
 
Meetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son applicationMeetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son applicationThibault Even
 
Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in AngularYadong Xie
 
WCMTL 15 - Create your own shortcode (Fr)
WCMTL 15 - Create your own shortcode (Fr)WCMTL 15 - Create your own shortcode (Fr)
WCMTL 15 - Create your own shortcode (Fr)MichaelBontyes
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 AppFelix Gessert
 

Similar to Angular2 workshop (20)

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
ngNewRouter
ngNewRouterngNewRouter
ngNewRouter
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Angular 2
Angular 2Angular 2
Angular 2
 
angular fundamentals.pdf
angular fundamentals.pdfangular fundamentals.pdf
angular fundamentals.pdf
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
mean stack
mean stackmean stack
mean stack
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdf
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 
Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburg
 
Meetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son applicationMeetup SkillValue - Angular 6 : Bien démarrer son application
Meetup SkillValue - Angular 6 : Bien démarrer son application
 
Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in Angular
 
WCMTL 15 - Create your own shortcode (Fr)
WCMTL 15 - Create your own shortcode (Fr)WCMTL 15 - Create your own shortcode (Fr)
WCMTL 15 - Create your own shortcode (Fr)
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 

More from Nir Kaufman

Angular Prestige: Less-known API and techniques
Angular Prestige: Less-known API and techniquesAngular Prestige: Less-known API and techniques
Angular Prestige: Less-known API and techniquesNir Kaufman
 
Angular CLI custom builders
Angular CLI custom buildersAngular CLI custom builders
Angular CLI custom buildersNir Kaufman
 
Electronic music 101 for developers
Electronic music 101 for developersElectronic music 101 for developers
Electronic music 101 for developersNir Kaufman
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018Nir Kaufman
 
Angular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanAngular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanNir Kaufman
 
Boosting Angular runtime performance
Boosting Angular runtime performanceBoosting Angular runtime performance
Boosting Angular runtime performanceNir Kaufman
 
Decorators in js
Decorators in jsDecorators in js
Decorators in jsNir Kaufman
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular componentsNir Kaufman
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive formsNir Kaufman
 
Webpack and angularjs
Webpack and angularjsWebpack and angularjs
Webpack and angularjsNir Kaufman
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tipsNir Kaufman
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - ServicesNir Kaufman
 
Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Nir Kaufman
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing optionsNir Kaufman
 

More from Nir Kaufman (16)

Angular Prestige: Less-known API and techniques
Angular Prestige: Less-known API and techniquesAngular Prestige: Less-known API and techniques
Angular Prestige: Less-known API and techniques
 
Angular CLI custom builders
Angular CLI custom buildersAngular CLI custom builders
Angular CLI custom builders
 
Electronic music 101 for developers
Electronic music 101 for developersElectronic music 101 for developers
Electronic music 101 for developers
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018
 
Angular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanAngular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir Kaufman
 
Boosting Angular runtime performance
Boosting Angular runtime performanceBoosting Angular runtime performance
Boosting Angular runtime performance
 
Decorators in js
Decorators in jsDecorators in js
Decorators in js
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive forms
 
Angular redux
Angular reduxAngular redux
Angular redux
 
Webpack and angularjs
Webpack and angularjsWebpack and angularjs
Webpack and angularjs
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tips
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 

Recently uploaded

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[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.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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 BusinessPixlogix Infotech
 
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)wesley chun
 
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...apidays
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
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)
 
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...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Angular2 workshop

  • 1. THE ANGULAR2 WORKSHOP Nir Kaufman Build Your First Angular2 Application
  • 2. Nir Kaufman - Wrote a book about Angular2 - Play the Bass - Eat vegan food Head of AngularJS Development @ 500Tech
  • 3.
  • 5. GET A FEEL OF ANGULAR2 Understand Angular2 concepts Get your hands on Get a project that you can keep learning with
  • 13. AN ANGULAR2 APPLICATION UI IS A COMPOSITION OF COMPONENTS (reusable UI building blocks)
  • 16. THIMKING IN COMPONENTS APP TOP-NAVBAR CONTENT TABLES TABLE-VIEWTABLE-VIEWTABLE-VIEW wrapper component
  • 17. MOST BASIC COMPONENT import { Component } from 'angular2/core'; @Component({
 selector: 'App',
 template: ‘<h1>Hello Component!</h1>’
 })
 
 class App {} In JavaScript Use in HTML <body>
 
 <App></App>
 
 </body>
  • 18. INSTRUCTIONS copy the images folder from ‘_template’ to ‘ src/assets’ copy and paste custom css to ‘src/assets/css/app.css’ locate the ‘tables.html’ template inside the ‘_templates’ folder create basic components, one per file, with a selector that mach the component name and the corresponding template HANDS ON - ON YOUR OWN! Build our top level component tree for our restaurant application.
  • 20. COMPONENT COMPOSITION import {Component} from 'angular2/core';
 import {TopNavBar} from './top-navbar';
 import {Content} from './content';
 
 @Component({
 selector: 'app',
 directives: [Content, TopNavBar],
 template: `
 <top-navbar></top-navbar>
 <content></content>
 `
 })
 
 export class App {} import {Component} from "angular2/core";
 
 @Component({
 selector:'content',
 template:`<div class="container"></div>`
 })
 
 export class Content {} content.ts app.ts
  • 21. INSTRUCTIONS separate the angular bootstrap to it’s own file compose the components starting from the top app component review our application HANDS ON - ALL TOGETHER! Compose our component tree to build our first ‘screen’
  • 25. ORDER-VIEW- FORM NEW-ITEM-FORM ITEM-LIST ITEM-COMMENTS ITEM-BUTTONS On a real application, we will probably break this form to much more smaller components
  • 26. APP TOP-NAVBAR CONTENT TABLES TABLE- VIEW TABLE- VIEW TABLE- VIEW wrapper component ORDER-VIEW- FORM NEW-ITEM-FORM ITEM-LIST ITEM-COMMENTS ITEM-BUTTONS ORDER-HISTORY EXTENDING OUR COMPONENTS TREE
  • 27. INSTRUCTIONS checkout the 03_adding_components branch find the templates on ‘_template’ folder (already extracted) like before, keep each component on it’s on file you can group components sub-trees in folders HANDS ON - ON YOUR OWN! code the missing components, test them by putting them inside the content component
  • 30. IN ANGULAR2 WE GOT A BRAND NEW COMPONENT ROUTER
  • 31. BASIC ROUTING IN 4 STEPS set the <base href=“/"> tag use the RouterConfig on the root component use the RouterOutlet component as placeholder use the RouterLink directive for links
  • 32. THE ROUTER CONFIG 
 @RouteConfig([
 {path: '/', name: 'root', redirectTo: ['Tables']},
 {path:'/tables', name: 'Tables', component: Tables},
 {path:’/order/:id',name: 'OrderView', component: OrderView},
 {path:'/history', name: 'OrderHistory', component: OrderHistory}
 ])
 
 @Component({
 template: `
 <top-navbar></top-navbar>
 
 <div class="container">
 <router-outlet></router-outlet>
 </div>
 `
 })
 app.ts
  • 33. ROUTER LINKS <ul class="nav navbar-nav">
 <li><a [routerLink]="['/Tables']">tables</a></li>
 <li><a [routerLink]="['/OrderHistory']">tables</a></li>
 </ul>
  • 34. INSTRUCTIONS inject the ROUTER_PROVIDERS on application boot config the routs on the top-level app component and replace the content component with router-layout add router links to the top-navbar component HANDS ON - ALL TOGETHER! Define basic routes to our application to navigate through the tables and the history view
  • 36. WE NEED TO PASS THE TABLE ID AS A PARAMETER WHEN NAVIGATING TO THE ORDER-FORM
  • 37. WORKING WITH PARAMS export class TableView {
 
 constructor(private router:Router) {}
 
 editOrder(){
 this.router.navigate( ['OrderView', { id: 5 }] );
 }
 } table-view.ts export class OrderView {
 
 constructor(private routeParams:RouteParams) {}
 
 ngOnInit() {
 let tableId = this.routeParams.get('id');
 }
 } table-view.ts
  • 38. INSTRUCTIONS implement an ‘editOrder’ method on table-view component that uses the Router to navigate to the order-view with an id. extract the id param in the order-view component on the init phase and log it to the console HANDS ON - ALL TOGETHER! Route to the order-view component with an id param and pull this param on the view-order component.
  • 41. DATA MODELS import {Item} from './item'
 
 export class Order {
 
 private orderId: string;
 public created: Date;
 public diners: number;
 public items: Item[];
 private comments: string;
 private total: number;
 public paid: boolean;
 private closed: Date;
 
 public constructor(diners: number = 1) {
 this.orderId = Order.nextId();
 this.created = new Date();
 this.diners = diners;
 this.paid = false;
 this.total = 0;
 }
 Let’s build the order and the item interfaces in a folder named ‘types’
  • 42. THE RESTAURANT MANAGER Our restaurant logic needs a home. create a ‘services’ folder for it. import {Order} from "./order";
 import {Injectable} from "angular2/core";
 import {Router} from "angular2/router";
 
 export class Restaurant {
 
 private _orders;
 
 public constructor(private router:Router) {
 this._orders = mockOrders;
 }
 
 public get orders(){
 return this._orders;
 }
 
 public newOrder() {
 let _order = new Order(1);
 this._orders.push(_order);
 this.router.navigate( ['OrderView', { id: _order.id }] );
 }
 
 public getOrderById(orderId) {
 return this._orders.filter( order => order.id === orderId)[0];
 }
 
 public checkout(orderId){
 this._orders.find(order => order.id === orderId).checkout()
 }
 }

  • 43. DEPENDENCY INJECTION 101 In angular2 each component get it’s own Injector. The location of injection is important. APP TOP-NAVBAR CONTENT TABLES TABLE-VIEWTABLE-VIEWTABLE-VIEW Service Service
  • 45. INSTRUCTIONS make the business logic classes injectable extract the id Inject the restaurant class to the app component (application toot) use some core directives for binding data to our components cleanups and refactoring HANDS ON - ALL TOGETHER! Wire up our business logic to our components and use some core directives
  • 46. INSTRUCTIONS use the familiar angular curly braces syntax use the data pipe for formatting the date implement the ‘checkout’ method on order view. remove it from table-view HANDS ON - ON YOUR OWN! Bind the order object to the table-view component.
  • 48. PIPES Now, we like to filter our orders, and display just the ‘open’ tables on the dashboard. In angular2 we got Pipes. A class that implement a transform method, decorated with the @Pipe decorator. import {Order} from "../services/order";
 import {Pipe} from 'angular2/core';
 
 @Pipe({
 name: 'orderPipe'
 })
 
 export class OrderPipe {
 
 transform(orders) {
 return orders.filter( order => order.paid == false);
 }
 }

  • 49. INSTRUCTIONS create a ‘pipes’ directory create a file named ‘orderPipe’ implement the transform method to return only the orders that makes as open (paid = false) decorate with a @Pipe and declare it on the tables component HANDS ON - ALL TOGETHER! Let’s create a pipe for filtering the tables showing only the orders that that opened.
  • 52. INSTRUCTIONS bind the order id and diners count to the order view build a select box using ngFor get a reference to the ngForm and implement ngSubmit use ng-control to bind the selected value to the order HANDS ON - ALL TOGETHER! Let’s bind data and make our order form to work by using some core directives and Form directives
  • 54. INSTRUCTIONS pass the order to the item-list use the data pipe for formatting the date implement the ‘checkout’ method on order view. remove it from table-view add comments to order HANDS ON - ON YOUR OWN! Make the items list to work! show items and remove items. bonus: add comments.
  • 56. TALKING WITH SERVERS The Http module was re-written in angular2. while it’s favourite reactive programming b by depending on Rxjs, we can use it anyway we like.
  • 58. INSTRUCTIONS use HTTP PROVIDERS implement a get method to pull orders data implement a post method to save orders to the database bonus: create a dedicated service for http calls HANDS ON - ALL TOGETHER! Let’s bring orders data from the server.