gpt4 book ai didi

Angular 2 : Cannot find name 'Params'

转载 作者:行者123 更新时间:2023-12-02 03:43:24 26 4
gpt4 key购买 nike

订阅ActivatedRoute的参数时,收到错误找不到名称“Params”。我应该从哪个包导入它?

import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
import { RecipeService } from '../../services/recipe/recipe.service';
import { ActivatedRoute } from '@angular/router';

//我在这里缺少导入。只是不知道从哪个包加载。

@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 );
}

}

我搜索了文档: https://angular.io/guide/router我已经检查了该页面上“Params”的所有 25 个实例。我已经检查了同一页面上“导入”的所有 301 实例。任何时候都不会导入“Params”。

无需导入即可正常工作:

 (P)=> {...} 

这会导致错误:

(P:Params)=>{...} ?

问题是关于“P”的类型而不是 ACTIVATED_ROUTE.params 的类型,这是 Observable<Param> .

最佳答案

缺少导入:

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

关于 Angular 2 : Cannot find name 'Params' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47703364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com