Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何在angular2.0中将参数传递给routes_Typescript_Angular - Fatal编程技术网

Typescript 如何在angular2.0中将参数传递给routes

Typescript 如何在angular2.0中将参数传递给routes,typescript,angular,Typescript,Angular,我试图使用route params,但无法实现,因为导入Routeparams时会显示错误 我的模板 <h6 class="headingh6 nobottommargin"><a [routerLink]="['User',{{detail.firstname}}]"> {{detail.firstname}} </a></h6> 有人能帮我吗 我的路线 import {provideRouter, RouterConfig}

我试图使用route params,但无法实现,因为导入Routeparams时会显示错误

我的模板

    <h6 class="headingh6 nobottommargin"><a [routerLink]="['User',{{detail.firstname}}]">  {{detail.firstname}} </a></h6>
有人能帮我吗

我的路线

   import {provideRouter, RouterConfig} from '@angular/router';

  import {DemoPage} from './demo-page';

  import {User} from './components/user/user';


   export const routes: RouterConfig = [
   { path: '', redirectTo: '/login', terminal: true },
   { path: 'login', component:Login },
   { path: 'signup', component:SignUp },
   { path: 'demo', component: DemoPage, children: [
     { path: 'user', component:User },
     { path: 'requests', component:Requests },
   ]}
];

 export const APP_ROUTER_PROVIDERS = [
    provideRouter(routes)


  ];
另见


另请参见

是否只想读取查询字符串参数

如果是,请使用此选项

constructor(private route: ActivatedRoute) {
      console.log(this.route.snapshot.params.id);
   }
在导入中,您需要:

import { ActivatedRoute } from '@angular/router';

当然,如果在路由配置中您有
/:id

您是否只想读取Querystring参数,这将起作用

如果是,请使用此选项

constructor(private route: ActivatedRoute) {
      console.log(this.route.snapshot.params.id);
   }
在导入中,您需要:

import { ActivatedRoute } from '@angular/router';

当然,如果在路由配置中您有
/:id

您使用的是什么路由器版本,这将起作用?当前路由器版本中没有
RouteSegment
。可以有任何替代。三个是3(如果你算上ngrx路由器,那么是4)Angular2的不同路由器,每个路由器都有不同的版本。我更新了V3.0.0-beta.2(Angular2团队最新版本)路由器的答案。Angular2团队的其他两个路由器已弃用。当我运行它时,它会显示错误“无法绑定到'routerLink',因为它不是已知的本机属性”,您需要添加
@Component({…,directives:[ROUTER\u directives]
})`在要使用
路由器链接的组件上。您使用的路由器版本是什么?当前路由器版本中没有
RouteSegment
。可以有任何替代。三个是3(如果你算上ngrx路由器,那么是4)Angular2的不同路由器,每个路由器都有不同的版本。我更新了V3.0.0-beta.2(Angular2团队最新版本)路由器的答案。Angular2团队的其他两个路由器已被弃用。当我运行它时,它显示错误“无法绑定到'routerLink',因为它不是已知的本机属性”,您需要在要使用
routerLink
的组件上添加
@Component({…,directives:[ROUTER\u directives]
})。
import { ActivatedRoute } from '@angular/router';