angular2 and you

13
Angular 2 and You

Upload: joseph-jorden

Post on 12-Jan-2017

132 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Angular2 and You

Angular 2 and You

Page 2: Angular2 and You

Back to Where it All Began

Angular 1.x description Watchers Controllers, views, services, etc. Digest Cycle (checks for changes up and down)

Page 3: Angular2 and You

What’s New?

Component – These are the main blocks to create apps with. It contains logic and the view.

Directive – Similar to component, but has no template. Just makes additional operations to the existing DOM elements.

Pipe – Gives you the ability to process variables in templates in a specific manner. Service – Injectable class used to share logic between components. Forms – A complex solution for handling forms in the app. HTTP – A service built on top of the observables to handle the connection between the

front end and the API. Router – Now routing directly to the components.

Page 4: Angular2 and You

What’s Missing?

No digest cycle (now uses directional graph) No $Scope

Page 5: Angular2 and You

Lingua Franca

Default demo written in TypeScript Can use JavaScript or Dart (if you work for Google)

TypeScript is a superset of JavaScript that compiles into plain old JavaScript It is compiled: you can catch errors before code runs Type safety: unlike Javascript you can enforce types Closer to OOP: you can use inheritance much easier

Page 6: Angular2 and You

Enough Theory

It is code time!

Page 7: Angular2 and You

Quick Start

Very basic app, displays a message Index.html loads system.config.js System.config.js configures app object

Points to main.js in app folder Main opens app.module via bootstrap App.module opens app.component via bootstrap App.component displays message

Selector targets tag in index.html Template inserts html in place of tag

Page 8: Angular2 and You

Hero Editor

More complex app.component Multiline template (note the ` character) Properties on AppComponent (replaces $scope)

Data usage Uses handlebars {{property}} to display data Uses [(ngModel)] to databind

Page 9: Angular2 and You

Master/Detail

Adding Hero object hero-detail component

Importing hero-detail component in app.module In app.component

Adding hero data Modifying template and styles

Notice *ngFor [class.selected] (click)

Page 10: Angular2 and You

Multiple Components

Adding new components for each object In app.module

Import herodetailcomponent Add herodetailcomponent declaration n

In app.component <my-hero-detail [hero]="selectedHero"></my-hero-detail>

Matches herodetailcomponent selector

Page 11: Angular2 and You

Services

Adding Hero service Mock heroes

In app.component Importing hero service Adding provider Implementing OnInit

Page 12: Angular2 and You

Routing

Change heroescomponent to appcomponent and make it a shell Add routing

Configure routes Add the dashboard

Page 13: Angular2 and You

HTTP

Provides access to web apis Not an integral part of Angular, must be imported separately