我正在尝试从 Angular2 组件中的 url 获取查询参数
版本:“angular2”:“npm:angular2@2.0.0-beta.12”,
我正在尝试在组件中提取 id 查询参数并显示它
这是请求。
本地主机:8080/index.html?id=1
引导.ts
import 'reflect-metadata';
import 'angular2/bundles/angular2-polyfills';
import { bootstrap } from 'angular2/platform/browser';
import { provide} from 'angular2/core';
import { AppComponent } from './app.component';
import {ROUTER_PROVIDERS, Location, LocationStrategy, HashLocationStrategy} from "angular2/router";
import {HTTP_PROVIDERS} from "angular2/http";
bootstrap(AppComponent , [ROUTER_PROVIDERS, HTTP_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy})]);
这是 app.component.ts
import { Component } from 'angular2/core';
import {Router, Location, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams} from 'angular2/router';
@Component({
selector: 'my-app',
template: '{{welcome}} {{queryParam}}',
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent {
welcome: string = 'Query Param test!'
queryParam : string;
constructor(private _location: Location, private _routeParams: RouteParams){
console.log(_routeParams.get('id'));
this.queryParam = _routeParams.get('id');
}
}
我不断收到此错误:
我从另一篇文章中得到了这个解决方案。不知道如何修复错误
一种