我目前正在使用HTTPClient学习Angular 6和RXJS。
文档指出,您可以使用pipe然后使用tap来捕获this.http.get方法中的错误,就像下面从官方文档中摘录的示例一样。
getTextFile(filename: string) {
// The Observable returned by get() is of type Observable<string>
// because a text response was specified.
// There's no need to pass a <string&
使用RxJs 6
以下是RxJs管道的摘录:
.pipe(
tap((action) => console.log(action)),
// error is on following line
withLatestFrom(this.store.pipe(select(selectBim(action.payload)))),
...
)
我的IDE中的错误是Cannot find name 'action',运行时错误是action is not defined。
但在withLatestFrom中,我需要访问action。我该怎么做?Thx
我正在编写以下代码:
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {Observable} from 'rxjs';
import {AngularFireAuth} from '@angular/fire/auth';
import {map, tap} from
我正在将我的代码转换为使用RxJS6语法来使用管道和映射,但是我得到了错误。
error TS2345: Argument of type '(error: any) => void' is not assignable to parameter of type '(err:
any, caught: Observable<void>) => ObservableInput<{}>'.
Type 'void' is not assignable to type 'ObservableInput<
我试图通过.pipe方法添加一个令牌
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { User } from './interfaces';
@Injectable()
export class AuthServ
当TypeScript编译具有超过9个管道操作符可观察到的代码时,它会抛出一个类型分配错误。只有在启用strictFunctionTypes选项时才会发生这种情况。
Argument of type '(...) => void' is not assignable to parameter of type '(value: {}) => void'.
Types of parameters '...' and 'value' are incompatible.
Type '{}' is mis
我的问题标题可能不是很清楚,让我澄清更多,欢迎你改进它。
我有一个角度应用程序,每隔几秒钟轮询一组数据。现在我有一个可以观察到的计时器,并且在另一个地方订阅。
public readonly people$ = timer(3, 10000).pipe(
switchMap(()=> this.http.get(url).pipe(tap(()=>{
//here is some business logic
//then at the end here I want to send a request unrelated to main busines