Angular 角度获取查询参数
我需要将下一个url发送到组件:Angular 角度获取查询参数,angular,angular2-routing,Angular,Angular2 Routing,我需要将下一个url发送到组件: http://localhost:3000/interactive/malenkoe_obyavlenie?device_type=phone 我下一步尝试: @NgModule({ imports: [ RouterModule.forChild([ { path: ':id?device_type', component: InteractivePreviewComponent } ]), Common
http://localhost:3000/interactive/malenkoe_obyavlenie?device_type=phone
我下一步尝试:
@NgModule({
imports: [
RouterModule.forChild([
{
path: ':id?device_type',
component: InteractivePreviewComponent
}
]),
CommonModule
],
declarations: [InteractivePreviewComponent]
})
但这是行不通的。
path:':id/:device_type*,
-在本例中,我使用了这个模块,但它带来了另一种url格式
http://localhost:3000/interactive/malenkoe_obyavlenie/phone
UPD:我的目标是获取“queryParams”。我在ActivatedRoute的不同字段中找到了
queryParams
:
this.routeParamsSubscription = this.route.params.subscribe(params => {
//get id from params
if(params['id']) {
this.slug = params['id']
//subscribing to change queryParams
this.routeParamsSubscription = this.route.queryParams.subscribe(params => {
// get query params this!
this.init(this.slug, params['device_type'])
})
}
})
关于此主题的好教程:
路由不是基于查询参数,它们是从组件中激活的路由获得的额外信息。例如,在AngularJS中,这非常容易
$stateProvider.state('incents-list',{url:'/incents?page&perPage&on&state})
,我认为在Angular2中它也一定能工作。可能重复