gpt4 book ai didi

angular - 类型 'subscribe' 上不存在属性 'OperatorFunction'

转载 作者:太空狗 更新时间:2023-10-29 18:02:52 24 4
gpt4 key购买 nike

我正在尝试从 firebase 获取数据,但遇到错误

"Property 'subscribe' does not exist on type 'OperatorFunction'"

有什么想法吗?这里缺少什么?

import { Injectable } from '@angular/core';
import {HttpClient, HttpResponse} from '@angular/common/http';
import {Response} from '@angular/http';
import {RecipeService} from '../recipes/recipe.service';
import {Recipe} from '../recipes/recipe.model';
import {map} from 'rxjs/operators';


@Injectable({
providedIn: 'root'
})
export class DataStorageService {

constructor(private httpClient: HttpClient,
private recipeService: RecipeService) {}

storeRecipes() {
return this.httpClient.put('https://ng-recipe-10b53.firebaseio.com/recipes.json',
this.recipeService.getRecipes());
}

getRecipes() {
this.httpClient.get('https://ng-recipe-book.firebaseio.com/recipes.json');
map(
(response: Response) => {
const recipes: Recipe[] = response.json();
for (const recipe of recipes) {
if (!recipe['ingredients']) {
recipe['ingredients'] = [];
}
}
return recipes;
}
)
.subscribe(
(recipes: Recipe[]) => {
this.recipeService.setRecipes(recipes);
}
);
}

}

最佳答案

有一件事打动了我,许多函数都有静态版本和可管道版本。

例如,combineLatest(a$, b$).subscribe()会给你一个关于 OperatorFunction<T,R> 的类似错误(T 和 R 将根据您的观察值而变化)如果您从 rxjs/operators 导入它!从 rxjs 导入它没问题。

如果您正在玩弄某些东西,您的 IDE 可能会很好地从 rxjs/operators 自动导入,并且当您尝试在管道外使用它时不会更改它。

关于angular - 类型 'subscribe' 上不存在属性 'OperatorFunction<Response, Recipe[]>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50398107/

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