observable

How to set multiple EnvironmentObjects which are same type

谁说我不能喝 提交于 2020-07-30 05:38:30
问题 I found this question SwiftUI: Putting multiple BindableObjects into Envionment the answer said environmentObject(ObservableObject) returns modified view, therefore I can make call chain for multiple environmentObject. like let rootView = ContentView() .environmentObject(firstBindable) .environmentObject(secondBindable) and I wonder what is result if firstBindable and secondBindable are same type. how .environmentObject() knows what is exect value which is a programmer intended to set between

RXJS: Combining multiple calls from foreach into a single observable

白昼怎懂夜的黑 提交于 2020-07-22 06:09:29
问题 I've been trying to combine multiple async calls for a while now, and everytime I get close, I get stuck at a foreach loop I'm trying to solve. At the moment I pass an array of categories to a function, which will return an observable containing an array of all the questions (of all the categories combined). I was thinking of getQuestions(categories: Category[]): Observable<Question[]> { let q: Question[]; categories.forEach(c => { this.cs .getQuestionsCategory(c.id) .pipe(map(questions => q

How to pass observed properties to other classes?

喜夏-厌秋 提交于 2020-07-22 03:31:25
问题 I created an instance of UserData so that other classes can observe this instance and show the necessary information by using the username. What I am trying to do here is, when a user is logged in, different classes with user related stored properties will be updated ( i.e. by calling the api) from time to time according to the user activity in the app. However, it shows the error 'Cannot use instance member 'userData' within property initializer; property initializers run before 'self' is

Angular Observable need to complete first

房东的猫 提交于 2020-07-22 03:24:26
问题 @Input() list: string[]; ngOnInit() : void { this.valueMap = new Map<any, any>(); this.getDataFromService(); this.buildContainer(); } private getDataFromService(): void { this.list.forEach(value-> { this.fetchService(value).subscribe(data ->{ this.valueMap.set(value,data); } ) }) } private buildContainer(): void { console.log(this.valueMap.size); // shows always 0 even when service returns the data } Now thing is that I have to use this valueMap in the method buidlContainer() , hence I need

Angular Observable need to complete first

喜你入骨 提交于 2020-07-22 03:23:16
问题 @Input() list: string[]; ngOnInit() : void { this.valueMap = new Map<any, any>(); this.getDataFromService(); this.buildContainer(); } private getDataFromService(): void { this.list.forEach(value-> { this.fetchService(value).subscribe(data ->{ this.valueMap.set(value,data); } ) }) } private buildContainer(): void { console.log(this.valueMap.size); // shows always 0 even when service returns the data } Now thing is that I have to use this valueMap in the method buidlContainer() , hence I need

RxJs: Executing 3 observables one after another and using results from first in second, and first and second in third requests

孤街浪徒 提交于 2020-07-20 11:30:58
问题 I need to be able to execute 3 observables one after another so that I can use result value from 1st one in second and also 1st and 2nd result in the third one. Something like this ( it doesn't work as the serviceId is not visible in the third request ): private setupStuff(): void { this.initRouteParams().pipe( switchMap(serviceId => this.getFileInfo(serviceId)), switchMap(fileName => this.getExistingFile(serviceId, fileName) .subscribe(response => { console.log(response); })) ); } 回答1: You

RxJs switchMap with angular HttpClient

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-19 00:56:49
问题 I have a use case whenever a new request is triggered, any http requests that are already in flight should be cancelled / ignored. For eg : A request (say #2) comes in while the request #1 takes too long to respond / slow network connectivity. In this case #2 gets a very quick response from server then at any point even if the #1 comes back with a response the HTTP response observable should be ignored. The problem i face is, first the component displays response values from request #2 and

How to cancel / close a behavior subject in angular

最后都变了- 提交于 2020-07-18 06:46:10
问题 I have a component that is subscribed to a behavior subject in the ngOnInit life cycle. This component html uses ngIf to see if data is there before rendering the table. When I navigate away from the page, I am wanting to make sure that the next time I come back, the table isn't visible until that data is then fetched again. The only way I have been able to do this so far is by calling next on the subject and sending an empty string, which feels wrong.. Component: mapMetaData: any; ngOnInit()

Async Pipe in Template inside ngFor block triggers http GET calls loop

断了今生、忘了曾经 提交于 2020-06-27 10:13:33
问题 I have the following component Template: <div *ngFor="let ctrl of data; trackBy:ctrl?.Id"> <div *ngIf="getNext(ctrl.nextDate) | async as next"> <span>{{next | date: 'dd.MM.yyyy'}}</span> </div> </div> getNext() is a simple method returning an Observable<Date> : public getNext(deadline: string): Observable<Date> { return this.http.get<Date>(`${this.config.apiEndpoint}/api/meeting?deadline=${deadline}`); } My goal would be to invoke the method and subscribe to the observable with the async pipe

How to wait for a http request to finish in Angular?

自闭症网瘾萝莉.ら 提交于 2020-06-24 08:45:27
问题 I've been building a SPA with Angular 4 on the front end and ASP.NET Core 2 on the Backend. Basically, I'm trying to automatically renew an user login, given a valid token. When I reload a page, for example, I would like that Angular stayed logged in. I'm storing the token on local storage, as well as an user object so I can check some user properties (if he/she is logged in for example). How should I force angular to wait for the http request to finish? Here's the .net get Service: get<T>