SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Dernier (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

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.