Angular2 rc1, new router and passing data

落爺英雄遲暮 提交于 2019-11-28 13:36:16

Wait for Angular2 to add the data back. In my case, a service that decides which data service is needed could be injected via DI. I found that to be an overkill, it simply is a passing parameters just like it's in URL query strings. The only difference was that the parameter shouldn't be visible to user for a better experience.

Source:

http://www.github.com/angular/angular/issues/8515

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
<a [routerLink]="['/crisis-center', {bar: 'foo1'}]">Crisis Center</a>
  • 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!