26
TypeScript & Angular 2 Love at first sight [email protected] [email protected]

TypeScript and Angular2 (Love at first sight)

Embed Size (px)

Citation preview

Page 1: TypeScript and Angular2 (Love at first sight)

TypeScript & Angular 2

Love at first [email protected]

[email protected]

Page 2: TypeScript and Angular2 (Love at first sight)
Page 3: TypeScript and Angular2 (Love at first sight)
Page 4: TypeScript and Angular2 (Love at first sight)

the future of JavaScript, now

TypeScript

Page 5: TypeScript and Angular2 (Love at first sight)

The feature gap

Page 6: TypeScript and Angular2 (Love at first sight)

The feature gap

Page 7: TypeScript and Angular2 (Love at first sight)

TypeScript• Free and open-source programming language developed and maintained by Microsoft.

• Designed for development of large applications; transcompiles to JavaScript.

• Superset of JavaScript; any existing JavaScript programs are also valid TypeScript

programs.

• Supports definition files that can contain type information of existing JavaScript libraries.

• TypeScript compiler is itself written in TypeScript.

• TypeScript is included as a first-class programming language in Microsoft Visual Studio

2013 Update 2 and later.

Page 8: TypeScript and Angular2 (Love at first sight)

Why add types to JavaScript?

• Types increase your agility when doing refactoring.

It's better for the compiler to catch errors than to have things fail at runtime.

• Types are one of the best forms of documentation you can have.

The function signature is a theorem, and the function body is the proof.

Page 9: TypeScript and Angular2 (Love at first sight)

Basic TypesBoolean

Number

String

Array

Tuple

Enum

Any

Page 10: TypeScript and Angular2 (Love at first sight)

Template Strings

• Multiline Strings

• String Interpolation

• Tagged Templates

Page 11: TypeScript and Angular2 (Love at first sight)

Arrow Functions

I hate JavaScript, as it tends to lose the meaning of this all too

easily!• You don't need to keep typing function.

• It lexically captures the meaning of this.

• It lexically captures the meaning of arguments.

Page 12: TypeScript and Angular2 (Love at first sight)

Things to Know about TypeScript• Types• Interfaces• Annotations/Decorators• async/await• Classes• Access Modifiers and Properties• Modules

• Static and Instance Members• Function Overloading*• Generics• Constructors• Inheritance• Interfaces

Page 13: TypeScript and Angular2 (Love at first sight)
Page 14: TypeScript and Angular2 (Love at first sight)
Page 15: TypeScript and Angular2 (Love at first sight)

“We love TypeScript for many things… With TypeScript, several of our team members have said things like ‘I now actually understand most of our own code!’ because they can easily traverse it and understand relationships much better. And we’ve found several bugs via TypeScript’s checks. “

– Brad Green, Engineering Director - AngularJS

Angular <3 TypeScript

Page 16: TypeScript and Angular2 (Love at first sight)

Transitioning from Angrular 1?So, you've skimmed a few lines of this new shiny Angular 2.0 thing, and you were like...

Eh?

Page 17: TypeScript and Angular2 (Love at first sight)

Why Angular 2?• Written in TypeScript.

• One framework. Mobile & desktop.

• Leading SPA framework with “batteries included”.

• Universal. Serve the first view from .NET, node.js, PHP for instant rendering in HTML and

CSS.

• Built on five years of community feedback.

• By focusing on standards, we get twice the power with half the framework.

Page 18: TypeScript and Angular2 (Love at first sight)

Building blocks• Modules

• Components

• Services

• Directives

• Data Binding

• Dependency Injection

Page 19: TypeScript and Angular2 (Love at first sight)

Basic Componentimport { MyService } from ‘./my.service.ts’;

@Component({

selector: ‘my-component’,

template: `

<h1>{{title}}</h1>

`

})

export class MyComponent {

constructor(public myService: MyService) {…}

}

Page 20: TypeScript and Angular2 (Love at first sight)

Data Binding

ComponentTemplate

Interpolation{{value}}

Property Binding[property]=“value”

Event Binding(event)=“handler”

Two Way Binding

[(ngModel)]=“value”

Page 21: TypeScript and Angular2 (Love at first sight)

Template syntax• Interpolation – {{expression}}• Method Binding - (event)=“expression”• Property Binding - [property]=“expression”• Two Way Binding - [(target)]=“expression”• Hashtag Operator - #item – local variable in the template scope.• Asterisk Operator - *ngIf – a directive that modifies the HTML.• Elvis Operator (?.) – {{component?.property}} – safe navigation operator.

Page 22: TypeScript and Angular2 (Love at first sight)

Architectural Best Practices• Include all files pertinent to a component in the same folder.• Remember CIDER for creating components: • Create class,• Import dependencies,• Decorate class,• Enhance with composition, • Repeat for sub-components.• Keep templates small enough to put the main component directly into the

file.• Delegate business logic from the component to a service.• Don’t be afraid to split a component up if it’s growing too large.• Lazy loading.

Page 23: TypeScript and Angular2 (Love at first sight)

• Server-side rendering (Universal)• Native mobile applications (NativeScript)• Web Browser• Desktop App (Electron)• Progressive web apps (web workers, cache, push,

offline)• Hybrid mobile apps (ionic)

One platform to rule them all

Page 24: TypeScript and Angular2 (Love at first sight)

Learning resources

https://mva.microsoft.com - Microsoft Virtual Academy

https://www.typescriptlang.org - State of the art JavaScript

https://angular.io - A step-by-step which introduces the major features of Angular

Page 25: TypeScript and Angular2 (Love at first sight)
Page 26: TypeScript and Angular2 (Love at first sight)

Thank You!

[email protected]@it-labs.com

http://it-labs.com