我是Angular单元测试的新手。我在服务中使用了new Subject<void>()
,但无法为其编写茉莉花代码。
service.ts文件
public _refreshNeeded = new Subject<void>();
get refreshNeeded() {
console.log(this._refreshNeeded)
return this._refreshNeeded;
}
getDetails() {
return this.httpClient.get<Data[]>(`${this.API_URL}`);
}
postDetails(user: Data, seqcode: any): Observable<Data[]>{
return this.httpClient.post<Data[]>(`${this.API_URL}`, user).pipe(tap(()=> {
this._refreshNeeded.next()
}));
}
component.ts文件
ngOnInit() {
this.corpTrustService._refreshNeeded.subscribe(() => {
this.getDetails();
});
this.getDetails();
}