observable

RxJava introduced Single<T>. How do I convert an Observable<T> to a Single<T>?

落花浮王杯 提交于 2020-04-29 07:17:57
问题 RxJava recently introduced Single. Is there a way to convert an already existing Observable (that's pretty much a Single) to a Single without modifying the source of the original observable? For example, I have an api service class with a method that returns an Observable - which is essentially fetching a User from a remote resource. Say I can't modify the service. I want to consume this elsewhere but return a Single. How do I do this? A pinch more background RxJava recently introduced the

Return nested forkjoins as observable

北城以北 提交于 2020-04-18 12:31:24
问题 I'm trying to return a bunch of nested forkjoins and normal subscribes in my resolver. For this I tried using maps, but I think I don't fully grasp the concept of maps/switchMaps/mergeMaps yet. I know the code doesnt return a UserResult yet, this is because I have no idea yet how I will add questionAnswers to the UserResult, but this shouldn't be that much of a difference for my current problem. My goals is to rewrite this, so that it returns an observable. resolve(route:

How to subscribe asynchronously to matdialog service for candeactivate guard?

二次信任 提交于 2020-04-17 22:16:07
问题 I have implemented candeactivate guard using angular forms validation. If user clicks on an ngForm Field. and tries to navigate to different Tab, user will get a custom confirmation Popup, which will say "Discard Changes ? " and returns true or false. This is my form guard import { NgForm } from "@angular/forms"; import { ComponentCanDeactivate } from './component-can-deactivate'; export abstract class FormCanDeactivate extends ComponentCanDeactivate { abstract get form(): NgForm;

Type 'Subscription' is missing the following properties from type 'Observable<StringMap<any>>'

╄→гoц情女王★ 提交于 2020-04-16 02:39:53
问题 ERROR : Type 'Subscription' is missing the following properties from type 'Observable>': _isScalar, source, operator, lift, and 6 more.ts(2740) Here I have attached my code. Here, in my case, I have two methods which return an observable, but getByTypeData and getByType. But, on returning this.getByType(type).. from getByTypeData() I am getting above error. P.S.: I want to subscribe getByTypeData in my component which should return me an observable. AND I AM NEW TO RXJS... /* interface

Should I always use Observables where a promise can be used?

℡╲_俬逩灬. 提交于 2020-04-13 14:51:35
问题 I posted a question on stack overflow yesterday where I asked the userbase if there was a way to await the result of an async operation without explicitly using the async and await keywords. The reason being that I needed to wait for the operation to complete so that I could use the value returned before any other HTTP requests could be fired. It turns out there was, it involved using observables to subscribe to the result of the operation, and to then use a mergeMap to continue on with the

SwiftUI -> Thread 1: Fatal error: No observable object of type MyObject.Type found

旧街凉风 提交于 2020-04-07 12:46:33
问题 I'm building an app with SwiftUI. When I was trying to display a sheet (previously Modal), this error message appears: Thread 1: Fatal error: No observable object of type BixiStationCombinedListViewModel.Type found. A View.environmentObject(_:) for BixiStationCombinedListViewModel.Type may be missing as an ancestor of this view. This error occurs when I'm using a @State variable to display a modal that includes a Map View using MapKit. I'm new to Swift Programming and SwiftUI. The error

How to use BehaviourSubjects to share data from API call between components in Angular?

蓝咒 提交于 2020-04-07 08:09:06
问题 I am currently building an Angular application where I make a request to an api, and I map the repsonse to two different arrays. I can use this data in my app.components.ts but I will make new components for what I need. How can I share the data between components to ensure that the components always have the latest data because I will also need to periodically call the API. I've seen some answers on SO and some youtube videos but I'm just not fully understanding it. The code of my service is

Property 'switchMap' does not exist on type 'Observable<User>'

匆匆过客 提交于 2020-03-18 04:01:07
问题 I have been getting the following error message when trying to apply the switchMap operator to my Observable: Property 'switchMap' does not exist on type 'Observable'. I'm currently using rxjs version 5.5.2, and in my component, I have it imported like so: import 'rxjs/operator/switchMap'; However, I still get a compilation error. I have looked at similar questions and have not found a proper solution to this, any suggestions on what could be the issue here? get appUser$() : Observable

Angular Auth Guard with Subscribe

谁说胖子不能爱 提交于 2020-03-05 06:05:43
问题 I have an auth guard and need to run an api call to see if they have access. I don't believe it's possible to return data from a subscribe but how else would I do this? I need to get the userid and then call the api and then return either true of false depending on the api call. import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; import { Observable } from 'rxjs'; import { AuthService } from 'src/app

ObservableObject bug or not

为君一笑 提交于 2020-03-03 07:47:48
问题 I still have the problem when the count reaches 3, the reset function only stops it, but the count is not set to 0. I use the reset function with a button, it works perfectly. i would like to understand it and hope someone knows the reason for it? import SwiftUI import Combine import Foundation class WaitingTimerClass: ObservableObject { @Published var waitingTimerCount: Int = 0 var waitingTimer = Timer() func start() { self.waitingTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: