标签: rxjs6

Angular - "没有导出的成员'Observable'"

码

错误信息

打字稿代码:

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

}
Run Code Online (Sandbox Code Playgroud)

错误信息:

错误TS2307:找不到模块'rxjs-compat/Observable'.node_modules/rxjs/observable/of.d.ts(1,15):错误TS2307:找不到模块'rxjs-compat/observable/of'.src/app/hero.service.ts(2,10):错误TS2305:模块'"F:/ angular-tour-of-heroes/node_modules/rxjs/Observable"'没有导出成员'Observable'.src/app/hero.service.ts(15,12):错误TS2304:找不到名称'of'.

package.json Angular版本的文件:

版

rxjs typescript angular angular6 rxjs6

138
推荐指数
8
解决办法
14万
查看次数

升级到 Angular 10 - 修复 CommonJS 或 AMD 依赖项可能导致优化救助

我正在尝试将我的 angular 9 应用程序升级到 angular 10 版本,但在升级后低于警告

rxjs\BehaviorSubject.js depends on rxjs-compat/BehaviorSubject
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

javascript rxjs angular-upgrade angular rxjs6

89
推荐指数
7
解决办法
10万
查看次数

无法在RxJs 6和Angular 6中使用Observable.of

 import { Observable, of } from "rxjs";

// And if I try to return like this
  return Observable.of(this.purposes);
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说明,'''类型'不存在'Observable'属性'

angular angular-observable rxjs6

54
推荐指数
1
解决办法
4万
查看次数

角度'Observable <Event>'上不存在Angular 6 router.events.filter'filter'

我已经完成了将我的应用程序更新为Angular 6(它是在5.2版本中).

我有一个错误语法:

import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
...
constructor(private router: Router) {}

this.router.events.filter
      (event => event instanceof NavigationEnd).subscribe((res) => 
    {
      // DO something
    });
Run Code Online (Sandbox Code Playgroud)

错误TS2339:类型'Observable'上不存在属性'filter'.

Angular 6中的语法是什么?

谢谢

rxjs typescript angular angular6 rxjs6

36
推荐指数
2
解决办法
3万
查看次数

不推荐使用forkJoin:不推荐使用resultSelector,而是使用pipe来映射

我正在开发一个Angular 6项目.

运行ng lint会发出以下警告:

"不推荐使用forkJoin:不推荐使用resultSelector,而是使用管道映射"

 forkJoin(...observables).subscribe(
Run Code Online (Sandbox Code Playgroud)

任何的想法?似乎无法找到有关此弃用的任何信息.

任何反馈都非常感谢.(downvoting没有多大帮助)

我刚刚使用Angular CLI生成了一个全新的Angular应用程序"ng new forkApp":6.1.5

资源:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { forkJoin } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'forkApp';

  constructor(private http: HttpClient) {}

  ngOnInit() {
    console.log('ngOnInit...');

    const obs = [];
    for (let i = 1; i < 4; i++) {

      const ob = this.http.get('https://swapi.co/api/people/' + i);
      obs.push(ob);

    }

    forkJoin(...obs)
      .subscribe( …
Run Code Online (Sandbox Code Playgroud)

angular rxjs6

34
推荐指数
4
解决办法
1万
查看次数

combineLatest弃用了静态combineLatest

使用后运行rxjs迁移工具

rxjs-5-to-6-migrate -p src/tsconfig.app.json

我现在得到一个linting错误:

combineLatest已弃用:不赞成使用static combineLatest.

在运行迁移命令之前,这是我的代码:

this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });
Run Code Online (Sandbox Code Playgroud)

运行迁移命令后的代码:(当前显示linting错误)

import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });
Run Code Online (Sandbox Code Playgroud)

问题在这个stackoverflow问题中被问到,但它不够具体:Angular 6 ng lint重复错误和警告,combineLatest已被弃用 .

rxjs rxjs6

32
推荐指数
4
解决办法
2万
查看次数

'Observable <IProduct []>'类型中不存在属性'do'

升级到Angular 6.0和Rxjs到6.0后,我收到以下编译错误:

Property 'do' does not exist on type 'Observable'.

这是代码:

import { Observable, of } from 'rxjs';
import 'rxjs/add/operator/do';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import { IProduct } from './product';

@Injectable()
export class ProductService { 
    constructor(
        private product: IProduct)
    {         
    }

    getProduct = () => { 
        return product.products
            // error on next line
            .do(data => console.log('All:' + JSON.stringify(data)))
            .catch(this.handleError);
    }

    private handleError(err: HttpErrorResponse) { 
        console.log(err.message);
        return Observable.throw(err.message);        
    }
}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

angular rxjs6

31
推荐指数
4
解决办法
3万
查看次数

Angular:如何使用RXJS 6调用finally()

我正在使用RXJS 5,现在当我升级到6时,我遇到了一些问题.

以前我能够使用catch和最后但是根据更新catch用catchError替换(在管道中)现在如何使用finally?

我也有一些问题:

我是否需要更改throw-> throwError(在下面的代码Observable.throw(err);)

import { Observable, Subject, EMPTY, throwError } from "rxjs";
import { catchError } from 'rxjs/operators';

return next.handle(clonedreq).pipe(
          catchError((err: HttpErrorResponse) => {
        if ((err.status == 400) || (err.status == 401)) {
            this.interceptorRedirectService.getInterceptedSource().next(err.status);
            return Observable.empty();
        } else {
            return Observable.throw(err);
        }
       }) 
        //, finally(() => {
        //  this.globalEventsManager.showLoader.emit(false);
        //});
      );
Run Code Online (Sandbox Code Playgroud)

另外如何使用publish().refCount()?

rxjs angular angular6 rxjs6

21
推荐指数
2
解决办法
1万
查看次数

在订阅中更改变量后,不会更新Angular 6 View

当变量在订阅中发生变化时,为什么视图没有更新?

我有这个代码:

example.component.ts

testVariable: string;

ngOnInit() {
    this.testVariable = 'foo';

    this.someService.someObservable.subscribe(
        () => console.log('success'),
        (error) => console.log('error', error),
        () => {
            this.testVariable += '-bar';

            console.log('completed', this.testVariable);
            // prints: foo-Hello-bar
        }
    );

    this.testVariable += '-Hello';
}
Run Code Online (Sandbox Code Playgroud)

example.component.html

{{testVariable}}
Run Code Online (Sandbox Code Playgroud)

但视图显示:foo-Hello.

为什么不显示:foo-Hello-bar

如果我ChangeDetectorRef.detectChanges()在订阅中调用它将显示正确的值,但为什么我必须这样做?

我不应该从每个订阅中调用此方法,或者根本不应该(angular应该处理这个).有正确的方法吗?

我是否遗漏了Angular/rxjs 5到6的更新内容?

现在我有Angular版本6.0.2和rxjs 6.0.0.相同的代码在Angular 5.2和rxjs 5.5.10中正常工作,无需调用detectChanges.

subscribe observable angular6 angular-changedetection rxjs6

20
推荐指数
3
解决办法
2万
查看次数

如何检测Angular应用程序中与rxjs相关的内存泄漏

是否有任何工具或技术来检测"留守"或"当前活着"的可观察量,订阅.

刚刚发现一个非常令人讨厌的内存泄漏,其中组件由于缺少"取消订阅"调用而保持活动状态.我读到了关于"takeUntil"的方法,看起来还不错. /sf/answers/2882401441/

但是我仍然想知道是否有任何工具(浏览器扩展等).据我所知,Augury并未涵盖这一领域.

所有输入都非常感谢.

javascript rxjs typescript angular rxjs6

20
推荐指数
1
解决办法
1895
查看次数