rxjs

Detecting change of a BehaviorSubject component member variable updated in a subscribe block?

匆匆过客 提交于 2021-01-16 04:32:33
问题 I have an element in a component view: <div>Progress: {{ progress$ | async }}</div> It is supposed to be updated in a continuous way by a next() call in a subscribe() block: progress$: BehaviorSubject<number> = new BehaviorSubject(0); downloadSoundtrack(soundtrack: Soundtrack): void { const fileName: string = soundtrack.name + '.' + MIDI_FILE_SUFFIX; const progress$: Observable<ProgressTask<Uint8Array>> = this.midiService.progressiveCreateSoundtrackMidi$(soundtrack); console.log('Created the

Detecting change of a BehaviorSubject component member variable updated in a subscribe block?

[亡魂溺海] 提交于 2021-01-16 04:26:14
问题 I have an element in a component view: <div>Progress: {{ progress$ | async }}</div> It is supposed to be updated in a continuous way by a next() call in a subscribe() block: progress$: BehaviorSubject<number> = new BehaviorSubject(0); downloadSoundtrack(soundtrack: Soundtrack): void { const fileName: string = soundtrack.name + '.' + MIDI_FILE_SUFFIX; const progress$: Observable<ProgressTask<Uint8Array>> = this.midiService.progressiveCreateSoundtrackMidi$(soundtrack); console.log('Created the

How to activate rxjs subscriber in one component from another angular component?

删除回忆录丶 提交于 2021-01-07 06:58:50
问题 componentA has subscriber of myService getData observable. componentB has the button. I want that after pressing this button next operations will appear: myService will make a call to the server and will get data; subscriber of componentA will process this data. I tried the folowing code: (myService) getData(): Observable<IData> { return this.http.get<IData>(apiUrl); } (componentA) ngOnInit() { this.myService.getData().subscribe(response => console.log(response)); } (componentB) public

Rxjs operator similar to combineLatest but that trigger if only one emit

旧城冷巷雨未停 提交于 2021-01-07 06:36:55
问题 In the RxJs doc of combineLatest , there is writtent: Be aware that combineLatest will not emit an initial value until each observable emits at least one value. Is there an operator that works like combineLatest but that emit a value even if only one of the observable emits a value ? 回答1: Assuming observables is an array of observables combineLatest(...observables.map( s => s.pipe( startWith(null) ) )).pipe( filter(arr => arr.filter(x => x != null).length > 0) ) This will emit an array with

Rxjs operator similar to combineLatest but that trigger if only one emit

不羁的心 提交于 2021-01-07 06:35:38
问题 In the RxJs doc of combineLatest , there is writtent: Be aware that combineLatest will not emit an initial value until each observable emits at least one value. Is there an operator that works like combineLatest but that emit a value even if only one of the observable emits a value ? 回答1: Assuming observables is an array of observables combineLatest(...observables.map( s => s.pipe( startWith(null) ) )).pipe( filter(arr => arr.filter(x => x != null).length > 0) ) This will emit an array with

Angular 2 Reset Observable Timer

我怕爱的太早我们不能终老 提交于 2021-01-05 09:46:38
问题 I have a service where I have a method getting called every 30 seconds automatically. I also have a button which will allow a user to reset the timer, preventing this method from getting called for another 30 seconds. How can I reset my timer so this method won't get called within that 30 seconds if the button is clicked? COMPONENT constructor(private service: Service) { this.service.initialize(); } refreshTimer(): void { this.service.refreshTimer(); } SERVICE initialize(): void { timer(0,

Array not updated when changes occur Angular 10

不打扰是莪最后的温柔 提交于 2021-01-05 09:11:56
问题 There is an Observable that sends an array of offers to my component. But when the list is changes (one is deleted) it does not change the list that I get in the component. I've tried it with ngOnChanges to subscribe to the list again and update the list in my component, but it doesn't detect any changes on the list. When I use ngDoCheck it worked, but I want a little less drastic solution for this.. offer.service.ts : // observable of offers list public getAll(): Observable<Offer[]> { return

Array not updated when changes occur Angular 10

只愿长相守 提交于 2021-01-05 09:11:41
问题 There is an Observable that sends an array of offers to my component. But when the list is changes (one is deleted) it does not change the list that I get in the component. I've tried it with ngOnChanges to subscribe to the list again and update the list in my component, but it doesn't detect any changes on the list. When I use ngDoCheck it worked, but I want a little less drastic solution for this.. offer.service.ts : // observable of offers list public getAll(): Observable<Offer[]> { return

How do I make a new call to an api when a previous one finished successfully?

无人久伴 提交于 2021-01-05 07:16:47
问题 I am new to angular and rxjs, and I have the following scenario, in which I need that after a call to an api is successfully resolved to make a new call, in the context of angular / rxjs I don't know how to do it handler(): void { this.serviceNAme .createDirectory(this.path) .pipe( finalize(() => { this.someProperty = false; }) ) .subscribe( (data) => console.log(data), (error) => console.error(error.message) ); } What is the correct way to make a new call to an api when a previous one was

Nest JS - Issue writing Jest Test Case for a function returning Observable Axios Response

十年热恋 提交于 2021-01-05 06:19:46
问题 I am fairly new to NestJS + Typescript + RxJs tech stack. I am trying to write a unit test case using Jest for one of my functions but not sure if doing it correctly. component.service.ts public fetchComponents(queryParams) { const url = this.prepareUrl(queryParams); const data$ = this.httpService.get(url); return data$ .pipe(map(({ data }) => data)); } component.sevice.spec.ts Test case works and passes describe('fetchComponents', () => { const query = { limit: 10, offset: 0 }; const result: