zoukankan      html  css  js  c++  java
  • [Angular] Router outlet events

    For example, we have a component which just simply render router-outlet:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'mail-app',
      styleUrls: ['mail-app.component.scss'],
      template: `
        <div class="mail">
          <router-outlet></router-outlet>
        </div>
      `
    })
    export class MailAppComponent {}
    export const ROUTES: Routes = [
      { path: 'folder/:name', component: MailFolderComponent }
    ];

    We can add events to router-outlet:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'mail-app',
      styleUrls: ['mail-app.component.scss'],
      template: `
        <div class="mail">
          <router-outlet
            (activate)="onActivate($event)"
            (deactivate)="onDeactivate($event)"
          ></router-outlet>
        </div>
      `
    })
    export class MailAppComponent {
      onActivate(event) {
        console.log(event)
      }
    
      onDeactivate(event) {
        console.log(event)
      }
    }

    When we log out the, we see the actual component been rendered into the router-outlet.

  • 相关阅读:
    第三章例3-3
    第三章例3-2
    第二章例2-11
    第二章例2-10
    第二章例2-9
    204
    205
    202
    203
    201
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6760023.html
Copyright © 2011-2022 走看看