好奇心からActivatedRoute
、数値として定義された変数に an の param を割り当てようとしました。
public id: number;
constructor(public activatedRoute: ActivatedRouter) {}
public ngOnInit() {
this.activatedRoute.params.take(1).subscribe((params) => {
this.id = params['id']; // I was expecting to see a warning here
}
}
...そして、IDE と tslint で警告なしに合格しました。だから私はそれを掘り下げて、要素を含むように宣言された ( here ) Paramsを発行することを発見しました:any
export type Params = {
[key: string]: any
};
そして、問題はなぜですか?私の知る限り、すべてのパラメーターは常に文字列です。number
パラメータの一部がorarray
である必要があり、それを解析することをAngular に伝える方法はありますか?