Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度观测值:在这个解决方案中,如何将参数传递给callWS()方法?_Angular_Typescript - Fatal编程技术网

Angular 角度观测值:在这个解决方案中,如何将参数传递给callWS()方法?

Angular 角度观测值:在这个解决方案中,如何将参数传递给callWS()方法?,angular,typescript,Angular,Typescript,使用和重置shareReplay的此解决方案来自: private\u refreshProfile$=新行为主体(未定义); 公共配置文件$:可观察=\u刷新配置文件$ .烟斗( switchMapTo(this.callWS()), 共享重播(1), ); 公共档案(){ 此。_refreshProfile$.next(); } 您可以使用switchMap。按如下方式使用: private _refreshProfile$ = new BehaviorSubject<number&g

使用和重置shareReplay的此解决方案来自:

private\u refreshProfile$=新行为主体(未定义);
公共配置文件$:可观察=\u刷新配置文件$
.烟斗(
switchMapTo(this.callWS()),
共享重播(1),
);
公共档案(){
此。_refreshProfile$.next();
}

您可以使用switchMap。按如下方式使用:

private _refreshProfile$ = new BehaviorSubject<number>(0);

public profile$: Observable<Customer> = _refreshProfile$
  .pipe(
    switchMap(userId => this.callWS(userId)),
    shareReplay(1),
   );

public refreshProfile(userId: number) {
    this._refreshProfile$.next(userId);
}

this.profile$.subscribe(console.log);
this.refreshProfile(20); // 20 will be passed as userId to callWS
private\u refreshProfile$=新行为主体(0);
公共配置文件$:可观察=\u刷新配置文件$
.烟斗(
switchMap(userId=>this.callWS(userId)),
共享重播(1),
);
公共刷新配置文件(用户标识:编号){
此._refreshProfile$.next(userId);
}
这个.profile$.subscribe(console.log);
本文件第(20)条;//20将作为userId传递给callWS

StackBlitz参考:

此.callWS(param1,param2,…)
?谢谢,但不是。您的解决方案没有获得外部参数…您好,请查看我添加的StackBlitz参考,它肯定有效。是的,工作正常!我的错,对不起,非常感谢!!
private _refreshProfile$ = new BehaviorSubject<number>(0);

public profile$: Observable<Customer> = _refreshProfile$
  .pipe(
    switchMap(userId => this.callWS(userId)),
    shareReplay(1),
   );

public refreshProfile(userId: number) {
    this._refreshProfile$.next(userId);
}

this.profile$.subscribe(console.log);
this.refreshProfile(20); // 20 will be passed as userId to callWS