gpt4 book ai didi

Angular - "has no exported member ' 可观察'”

转载 作者:太空狗 更新时间:2023-10-29 16:44:50 27 4
gpt4 key购买 nike

code

error info

typescript 代码:

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';

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

constructor() { }

getHeroes(): Observable<Hero[]> {
return of(HEROES);
}

}

错误信息:

error TS2307: Cannot find module 'rxjs-compat/Observable'. node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/observable/of'. src/app/hero.service.ts(2,10): error TS2305: Module '"F:/angular-tour-of-heroes/node_modules/rxjs/Observable"' has no exported member 'Observable'. src/app/hero.service.ts(15,12): error TS2304: Cannot find name 'of'.

package.json Angular 版本的文件:

version

最佳答案

这可能对 Angular 6 有帮助,有关更多信息,请参阅 Document

  1. rxjs:创建方法、类型、调度程序和实用程序
import { Observable, Subject, asapScheduler, pipe, of, from, interval, merge, fromEvent } from 'rxjs';
  1. rxjs/operators:所有管道运算符:
import { map, filter, scan } from 'rxjs/operators';
  1. rxjs/webSocket:网络套接字主题实现
import { webSocket } from 'rxjs/webSocket';
  1. rxjs/ajax:Rx ajax 实现
import { ajax } from 'rxjs/ajax';
  1. rxjs/testing:测试实用程序
import { TestScheduler } from 'rxjs/testing';

关于 Angular - "has no exported member ' 可观察'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49840152/

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