Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular2 with ASP.NET Core

Angular2 with ASP.NET Core

Avatar for David M Pine

David M Pine

April 07, 2017
Tweet

More Decks by David M Pine

Other Decks in Programming

Transcript

  1. AGENDA • Introduction • Set the stage • Angular2 •

    ASP.NET Core • The “I Do’s” – marriage ceremony • Question & Answers
  2. DAVID PINE { @davidpine7 } < TECHNICAL EVANGELIST /> •

    http://davidpine.net • https://github.com/ievangelist • http://stackoverflow.com/users/2410379/david-pine • https://www.linkedin.com/in/dpine
  3. SET THE STAGE T H E WO R L D

    - W I D E W E B ? !
  4. LEGACY WEB HyperText Markup Language [ HTML, 1993 ] Cascading

    Style Sheets [ CSS, 1996 ] JavaScript [ JS, 1995 ] Originally designed to serve as a static document. Applications were typically a few hundred lines at most…
  5. DEAD-TO-ME WEB ASP.NET Proper • WebForms – ViewState, Page Lifecycle,

    Postbacks, HTML abstraction, etc… • MVC – System.Web, Global mutable state, Page Load/Request, API vs MVC
  6. THINGS THEY GOT RIGHT MVC • Testable • Separation of

    concerns • Stateless • HTTP verbs • CSHTML (somewhat) WEBFORMS
  7. MODERN WEB / ARCHITECTURE Single Page Application [ SPA, 2003

    ] • Initial page load is a drag… ¯\_(ツ)_/¯ • Client-side routing • Full control over HTML • Closer to the problem domain (web dev)
  8. import { NgModule } from '@angular/core'; import { RouterModule }

    from '@angular/router'; import { UniversalModule } from 'angular2-universal'; import { AppComponent } from './components/app/app.component‘ import { HomeComponent } from './components/home/home.component'; @NgModule({ bootstrap: [ AppComponent ], declarations: [ AppComponent, HomeComponent ], imports: [ UniversalModule, // Imports BrowserModule, HttpModule, and JsonpModule RouterModule.forRoot([ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { path: '**', redirectTo: 'home' } ]) ] }) export class AppModule { }
  9. Angular Component are the most basic building block of an

    UI in an Angular application. app.component.ts COMPONENTS
  10. import { Component } from '@angular/core'; @Component({ selector: 'home', templateUrl:

    './home.component.html' }) export class HomeComponent { } <div> <home></home> </div> Component Class Impl Example Usage
  11. import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: date'

    }) export class DatePipe implements PipeTransform { transform(date: Date, format?: string): string { // Omitted for brevity ... } } <div> {{ dateOfBirth | date:shortDate }} // Outputs as 7/7/1984 </div> Pipe Class Impl Example Usage
  12. Angular Templates in Angular, the component plays the part of

    the controller/viewmodel, and the template represents the view. home.component.html TEMPLATING
  13. HTML Plus Interpolation ( {{...}} ) Template expressions Template statements

    Binding syntax Property binding ( [property] ) Attribute, class, and style bindings Event binding ( (event) ) Two-way data binding ( [(...)] ) Built-in directives Built-in attribute directives NgClass NgStyle NgModel ([(ngModel)]) Built-in structural directives NgIf NgFor Template input variables Microsyntax The NgSwitch directives Template reference variables ( #var ) Input and output properties ( @Input and @Output ) Template expression operators pipe ( | ) safe navigation operator ( ?. )