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

Cross Cutting Concerns in Angular -- Talk at do...

Cross Cutting Concerns in Angular -- Talk at dotnet cologne in Mai 2018

Avatar for Manfred Steyer

Manfred Steyer PRO

May 04, 2018
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. About me… • Manfred Steyer • SOFTWAREarchitekt.at • Angular Trainings

    and Consultancy • Google Developer Expert (GDE) Page ▪ 2 Manfred Steyer
  2. What are Guards? • Services • Can prevent the Activation

    or Deactivation of a Route Page ▪ 6
  3. Configure Guards Page ▪ 8 const APP_ROUTES: Routes = [

    { path: '/flight-booking', component: FlightBookingComponent, canActivate: [AuthGuard], children: [ { path: 'flight-edit/:id', component: FlightEditComponent, canDeactivate: [FlightEditGuard] }, […] ] ]
  4. Provider for Guards Page ▪ 9 @NgModule({ providers: [ FlightEditGuard,

    AuthGuard ], […] }) export class XYModule { }
  5. Idea • Providing a hook for HttpClient • Modify requests

    and responses globally • Including Headers, e. g. for Auth. • Parsing Data Formats, like XML • Error Handling • Caching • …
  6. Directive @Directive({ selector: '[clickWithWarning]' }) export class ClickWithWarningDirective implements OnInit

    { @Input() warning: string = 'Are you sure?'; @Output() clickWithWarning = new EventEmitter(); […] }
  7. Directive @Directive({ selector: '[clickWithWarning]' }) export class ClickWithWarningDirective implements OnInit

    { @Input() warning: string = 'Are you sure?'; @Output() clickWithWarning = new EventEmitter(); @HostBinding('class') cssClass: string = 'btn btn-danger'; […] }
  8. Directive @Directive({ selector: '[clickWithWarning]' }) export class ClickWithWarningDirective implements OnInit

    { @Input() warning: string = 'Are you sure?'; @Output() clickWithWarning = new EventEmitter(); @HostBinding('class') cssClass: string; @HostListener('click', ['$event']) handleClick($event): void { if (confirm(this.warning)) { this.clickWithWarning.emit(); } } }