observable

Observable fromEvent do not activate detectionChange on angular

孤者浪人 提交于 2021-01-29 18:01:10
问题 I have been trying to solve this problem for days: I'm doing an application that uses angular and electron, so I'm always in the production environment in angular. I use electron's ipcMain and ipcRender to communicate between the main process and the render to display csv files. The problem is that creating an observable fromEvent does not seem to trigger the angular changeDetection. Initially I solved the problem using ChangeDetectorRef but this creates strange behavior on the material

Mapping between two arrays of observable classes

回眸只為那壹抹淺笑 提交于 2021-01-29 12:54:46
问题 I have two given classes SgFormsBase and QuestionBase with slightly different member names, and I want to translate observable[] of one to the other. import { of, Observable } from 'rxjs' import { map} from 'rxjs/operators' class SgFormsBase{ constructor( public id: number, public survey: string ){} } class QuestionBase{ constructor( public qid: number, public qsurvey: string ){} } const a = new SgFormsBase(11, 'Endo') const b = new SgFormsBase(12, 'Kolo') const sg = of([a, b] ) function

Behaviour subject value is empty when trying to fetch from a second component

烂漫一生 提交于 2021-01-29 11:01:59
问题 I am trying to share data between two components in Angular 8 using BehaviourSubject and a shared service. The code in component 1 is shown below. constructor(private appSharedService: AppSharedService) { } ngOnInit() { this.appSharedService.getCars() .subscribe(response => { this.cars = response; this.appSharedService.updateCarsList(this.cars); }, error => { console.log(error); }); } The code in the shared app-shared service is export class AppSharedService { carsSubject : BehaviorSubject

What is the proper way to return from within an angular subscription?

旧时模样 提交于 2021-01-29 10:58:28
问题 Disclaimer: This is a "good programming practices" question rather than a "fix my broken code" question. Environment Angular 5.2.9, Angular Material 5.2.4, Typescript 2.4.2, Rxjs 5.5.8 Issue I am using the mat-dialog component of the angular material library, and subscribing to the observable returned from afterClosed(). Inside of that subscription I have a simple if statement. If value is returned, return value, otherwise return null. My tslint is throwing a fit about returning from inside

Angular - Rxjs Observable - Clicking event implementation

╄→尐↘猪︶ㄣ 提交于 2021-01-29 10:30:24
问题 I'm having trouble wrapping my head around implementing an Observable clicking event to a function I already implemented. The examples I have seen so far are implemented using the fromEvent or Subject like so; import {Subject} from "rxjs/Subject"; export class Component { private clickStream$ = new Subject<Event>(); @Output() observable$ = this.clickStream.asObservable(); buttonClick(event:Event) { this.clickStream$.next(event); } } their html <button type="button" (click)="buttonClick($event

Return value from subscribe in Ionic

南笙酒味 提交于 2021-01-29 10:11:56
问题 So I want to return a value from a subscribe function like this: async obtenerListadoClases(categoria) { var clasesDB = await this.getClases(categoria) .subscribe((data: any) => { clasesDB = data.clasesDB // **Want to return this** console.log(clasesDB,'clasesDB'); // **Getting Value** }) console.log(clasesDB, 'outside'); // **Not Getting Value** return clasesDB; } Also, I want to use this function in another place like this: var listaClases = await this.claseServicio.obtenerListadoClases

RxJS All Individual Observables completed

杀马特。学长 韩版系。学妹 提交于 2021-01-29 08:02:09
问题 I have an array of unique ID's and want to perform a bulk action (HTTP patch, delete etc) on them. That needs to be done individually and I need to display individual results. As the requests are individual and it's responses should not affect each other. Results are displayed as they are received. Every call is a separate Observable and what I'm looking for is a way to know when all Observables have completed . The onCompleted method works only when there are no errors. The goal is to

how to display @feathersjs-client results in Angular

假装没事ソ 提交于 2021-01-29 07:40:28
问题 In process to integrate feathersjs-client into an angular frontend using feathers-chat-angular code as a guide. Backend up and running: MongoDB, Mongoose, express/feathers server. Was able to retrieve data from the frontend, got stuck displaying the response data. Feathers-reactive currently not used. Warning beginner@work ... Was looking into Observables but always ran into: ERROR: Uncaught (in promise): TypeError: this.dataService.issues$(...).pipe... is not a function. Played around with

Converting Observable to Promise

筅森魡賤 提交于 2021-01-29 07:34:15
问题 Is it a good practice to convert the observable object to a promise since observable can be used in almost all the occasions instead of promise? I've started to learn angular recently and come across the below code snippet in a new project(Angular 5) at my workplace. This code snippet is used to load a list of data such as a customer list. This customer list data set is received as a one time action, not as a stream. Therefore it has no technical limitation to use promise. But I would like to

Why am I getting a “Failed: Cannot read property 'subscribe' of undefined” while running tests?

谁说胖子不能爱 提交于 2021-01-28 11:17:51
问题 I am relatively new to testing in Angular2+ and am setting up my files for testing. Since building the project, I've written a lot of code and am now trying to test parts of it. However, lots of those tests are now broken so I am now trying to delete the unneeded default tests or fix the ones that are useful. This particular test won't run because it fails before it hits the It() testing method. I'm not sure what I'm missing, any help would be appreciated. I am receiving this error: Failed: