30
Ross Dederer Angular 2

Migrating an Application from Angular 1 to Angular 2

Embed Size (px)

Citation preview

Page 1: Migrating an Application from Angular 1 to Angular 2

Ross Dederer

Angular 2

Page 2: Migrating an Application from Angular 1 to Angular 2

about: me Ross Dederer Developer Relations of Wijmo

We sell JavaScript UI controlso Gridso Chatso Inputs, etc

Always researching new frameworks

Page 3: Migrating an Application from Angular 1 to Angular 2

about: discussion What is Angular 2 – sharing experiences TypeScript

o Introduction o Comparison to JavaScript

Data Services Quick Start Application Type Safety Data Binding Migrating View to Angular 2 template

Page 4: Migrating an Application from Angular 1 to Angular 2

Real world sample

Page 5: Migrating an Application from Angular 1 to Angular 2

Angular 2 introduction Modular

o Smaller Core

Moderno Evergreen browsers using ECMA 6

Component Based TypeScript

o Transpiling

Documentation has two tracks Google will continue developing Angular 1.x

Page 6: Migrating an Application from Angular 1 to Angular 2

Angular 2 – first impressions Better Encapsulation – Components Better Performance – fast initial loads, server side pre –rendering, faster

change detection Angular 2 is actually simplier than Angular 1

o Delegates tasks to JS interpretor. o Leverages HTML5 more efficiently

Typescript Integration

Page 7: Migrating an Application from Angular 1 to Angular 2

From angular.io

Page 8: Migrating an Application from Angular 1 to Angular 2

TypeScript TypeScript was created by Microsoft ( FOSS ) Google is fully adopting TypeScript for Angular 2 development Superset of JavaScript that compiles to plain JS

o Any Browser, any host, any OS

Offers classes, modules, and interfaces Object Oriented with Classes etc Open Source Find errors at design time

Page 9: Migrating an Application from Angular 1 to Angular 2

Transpilation Source to source compilation

o Creates a map file

Why is it needed?o Modern browsers cant understand TS

Built into Visual Studio

Page 10: Migrating an Application from Angular 1 to Angular 2

IntelliSense

Feature of TypeScript o Not exclusive to Angular 2

C# developers utilize it heavily

Self documentation Self documentation

Page 11: Migrating an Application from Angular 1 to Angular 2

Module Application is a collection of Modules Optional – but recommended

o Need to us TypeScript ( ES2015 )

Angular provides us built in modules

export class PortingFromSL{ }

import {PortingFromSL} from './app';

import {Component,View} from 'angular2/core';

Page 12: Migrating an Application from Angular 1 to Angular 2

Component Controls patch of screen – View

Contains our class that interacts with the viewo Via api of properties and methods.

Each Component has a companion Template “Code-behind” for components View Angular creates updates and destroyes components

Page 13: Migrating an Application from Angular 1 to Angular 2

Templating Components View contains component Template A form of HTML ( not a HTML Form )

Angular manages the component and its view ( template ) All HTML is valid Template Synatx

Page 14: Migrating an Application from Angular 1 to Angular 2

Metadata and Decorators Decorators @component @view

MetaData Selector TemplateURL

Page 15: Migrating an Application from Angular 1 to Angular 2

Data Binding

Interpolation {{ }}

Template Expressions [property]=“expression”o Produces a value

Template Statements (event)=“statement”o Responds to event

Two-way Data Binding [(target)] = “expression”

Page 16: Migrating an Application from Angular 1 to Angular 2

Data Services QuickStart Application Loading Data into CollectionView

o Sort, filter, group

Managing Hierarchical data to reflect current state o Master Detail Relationships

Binding data to Wijmo Controls o Line of business application template

Live Demo: http://demos.wijmo.com/5/Angular/PortingFromSL/PortingFromSL/

Page 17: Migrating an Application from Angular 1 to Angular 2

The Silverlight App

Page 18: Migrating an Application from Angular 1 to Angular 2

Wijmo Controls used Wijmo.core Wijmo.grid Wijmo.input

o Input numbero Input dateo Combo box picker

Binding to all available control properties Two-way binding to properties Event Bindings Bindings for ngFor

Page 19: Migrating an Application from Angular 1 to Angular 2

Application Structure - New things In Ng 1, we needed to create a new app and give it a controller to handle

all of the business logic. o No more controllers in Ng 2

In Ng 2, we will organize our app inside a module that we will call PortingFromSL o We will leverage the benefits of TypeScript here

In Ng 2, we will move all of our markup and templating sits in app.html In Ng 2, we need to introduce a root component loader

Page 20: Migrating an Application from Angular 1 to Angular 2

Bootstrapping - Launching ApplicationFrom bootstrap.ts import {class} from './app'; bootstrap(class.component);

Inside default.htm System.import(“/src/class.component”);

Inside default.htm System.import(“/src/class.component”);

Page 21: Migrating an Application from Angular 1 to Angular 2

Migration from Angular 1 to Angular 2 Convert JavaScript to TypeScript Keep familiar MVVM development pattern

Porting the ViewModel - Component o No controller?o No $scope?

Porting the View o New attribute syntax

Page 22: Migrating an Application from Angular 1 to Angular 2

Porting the Model We luckily will use the same model/Datasource

o JSON coming from service can serve as model.

private _svcUrl: string = 'http://services.odata.org/Northwind/Northwind.svc';

Made my life really easy

Page 23: Migrating an Application from Angular 1 to Angular 2

Porting the ViewModel CollectionView objects for Customers, Orders, Details Load some data using AJAX Ng 2 More closely related to SL than NG1

Class App

customers: wijmo.collections.CollectionView; // or any

Constructor

this.customers = new wijmo.collections.CollectionView();

Page 24: Migrating an Application from Angular 1 to Angular 2

Porting the View *ngFor

In Angular 1Ng-click=“someEvent()” In Angular 2 (click)=“OnSave()”

<div *ngFor=“#qh of QueryResources, #index =index”> {{index}} {{qh.table}} </div>

In Angular 1Ng-click=“someEvent()” In Angular 2 (click)=“OnSave()”

<div *ngFor=“#qh of QueryResources, #index =index”> {{index}} {{qh.table}} </div>

Page 25: Migrating an Application from Angular 1 to Angular 2

Porting the View - Wijmo Data-binding

<wj-input-number [required]="false"

[(value)]="currentItem.Freight">

</wj-input-number>

<wj-flex-grid #flex class="grid" [itemsSource]="details">

Page 26: Migrating an Application from Angular 1 to Angular 2

Migrating the ‘Controller’export module portingFromSL {

@Component({

selector: 'app',

})

@View({

templateUrl: 'src/app.html',

directives: [ ]

})

export class App {

Page 27: Migrating an Application from Angular 1 to Angular 2

Default.htm<body>

<app></app>

<body>

Everything is a component

Think of a component as a single unit which is a model, a controller, and a view.

Page 28: Migrating an Application from Angular 1 to Angular 2

Live Demo

Page 29: Migrating an Application from Angular 1 to Angular 2

Conclusion

www.wijmo.com Angular.io

[email protected]

Page 30: Migrating an Application from Angular 1 to Angular 2

Thank You