J.M*_*SON 2 lambda routes subscribe angular
订阅 ActivatedRoute 的参数时,出现错误Cannot find name 'Params'。我从哪个包导入它?
import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
import { RecipeService } from '../../services/recipe/recipe.service';
import { ActivatedRoute } from '@angular/router';
Run Code Online (Sandbox Code Playgroud)
// 我这里缺少一个导入。只是不知道从哪个包加载。
@Component({
selector: 'app-recipe-detail',
templateUrl: './recipe-detail.component.html',
styleUrls: ['./recipe-detail.component.css']
})
export class RecipeDetailComponent implements OnInit {
recipe: Recipe;
id: number;
constructor (
private rService: RecipeService ,
private ACTIVATED_ROUTE: ActivatedRoute,
) {
}
ngOnInit() {
const id = this.ACTIVATED_ROUTE.snapshot.params['id'];
this.ACTIVATED_ROUTE.params.subscribe(
( P: Params ) => { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PROBLEM LINE
this.id = +P['id'];
this.recipe = this.rService.getRecipe( this.id );
}
);
}
onAddToShopList(){
this.rService.addIngredientsToShopList( this.recipe.ingredients );
}
}
Run Code Online (Sandbox Code Playgroud)
我搜索了文档: https: //angular.io/guide/router 我已经检查了该页面上“Params”的所有25 个实例。我已经检查了同一页面上所有301 个“导入”实例。任何时候都不会导入“Params”。
无需导入即可正常工作:
(P)=> {...}
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
(P:Params)=>{...} ?
Run Code Online (Sandbox Code Playgroud)
问题是关于“P”的类型而不是 的类型ACTIVATED_ROUTE.params
,后者是Observable<Param>
。