Angular2 rc1, new router and passing data

前端 未结 2 1114
星月不相逢
星月不相逢 2020-12-11 18:32

Used to have, with deprecated router, a few components that routed to the same component:

Some Component

import {Component, Injector         


        
2条回答
  •  情歌与酒
    2020-12-11 19:32

    update

    RC.4 brings data back

    • Passing data using routes
    { path: 'parent/:id', data: {one: 1}, resolve: {two: 'resolveTwo'}}
    

    and access it using

    this.route.snapshot.data
    

    or

    this.route
          .data
          .subscribe(v => console.log(v));
    

    See also the Plunker at https://github.com/angular/angular/issues/9757#issuecomment-229847781

    original

    Parameters can be passed like:

    • with a router link
    Crisis Center
    
    • with router.navigate()
    this.router.navigate(['/crisis-center', {bar: 'foo2'}]);
    

    Plunker example

    app/app.component.ts contains the links and code where parameters are passed, app/crisis-center/crisis-center.coomponent.ts contains the code where the parameter is read and written to the console.

    I don't think there is support for extra data anymore.

提交回复
热议问题