observable

Convert Observable<Object> to String

余生颓废 提交于 2021-01-24 07:13:10
问题 I've found this example of a service to get the IP-Address. This service returns an Observable<Object> , which I would like to assign/save to a String-Variable. getIpAddress() { return this.http .get('https://api.ipify.org/?format=json') .pipe( catchError(this.handleError) ); } I'm still not well "trained" with Observables. I've injected this Service to my own Service (an Authentication Service) where I'm trying to access the actual value, which would be a string. I know I'll have to

How to make synchronous HTTP request in Angular 8 or 9 (make a request and wait)

六月ゝ 毕业季﹏ 提交于 2021-01-07 02:30:44
问题 There are three buttons: Clicking the first Request HTTP Data As Promise button gets its HTTP response as a Promise . The second Request HTTP Data As Observable button gets its response as an Observable . Both these buttons get their responses using asynchronous response mechanism. Now, I would like the third Request HTTP Data and Wait button to get a synchronous response. I would like it to wait for the http service to return the HTTP response. How could it be done? Here is the link to the

How to make synchronous HTTP request in Angular 8 or 9 (make a request and wait)

爷,独闯天下 提交于 2021-01-07 02:28:10
问题 There are three buttons: Clicking the first Request HTTP Data As Promise button gets its HTTP response as a Promise . The second Request HTTP Data As Observable button gets its response as an Observable . Both these buttons get their responses using asynchronous response mechanism. Now, I would like the third Request HTTP Data and Wait button to get a synchronous response. I would like it to wait for the http service to return the HTTP response. How could it be done? Here is the link to the

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,

Updating value inside fragment from activity

☆樱花仙子☆ 提交于 2020-12-15 16:38:42
问题 I wish to transfere my old app to MVVM, so can you please help me with this test: Shared ViewModel: class SharedViewModel : ViewModel() { private var _numberF1 = MutableLiveData<Int>().apply { postValue(0)} val numberF1: LiveData<Int> get() = _numberF1 fun addNumberF1() { _numberF1.value = _numberF1.value?.plus(1) } } Fragment: class Fragment1 : Fragment() { companion object { fun newInstance() = Fragment1() } private lateinit var viewModel: SharedViewModel override fun onCreateView(inflater:

Updating value inside fragment from activity

心不动则不痛 提交于 2020-12-15 16:36:40
问题 I wish to transfere my old app to MVVM, so can you please help me with this test: Shared ViewModel: class SharedViewModel : ViewModel() { private var _numberF1 = MutableLiveData<Int>().apply { postValue(0)} val numberF1: LiveData<Int> get() = _numberF1 fun addNumberF1() { _numberF1.value = _numberF1.value?.plus(1) } } Fragment: class Fragment1 : Fragment() { companion object { fun newInstance() = Fragment1() } private lateinit var viewModel: SharedViewModel override fun onCreateView(inflater:

Updating value inside fragment from activity

独自空忆成欢 提交于 2020-12-15 16:35:06
问题 I wish to transfere my old app to MVVM, so can you please help me with this test: Shared ViewModel: class SharedViewModel : ViewModel() { private var _numberF1 = MutableLiveData<Int>().apply { postValue(0)} val numberF1: LiveData<Int> get() = _numberF1 fun addNumberF1() { _numberF1.value = _numberF1.value?.plus(1) } } Fragment: class Fragment1 : Fragment() { companion object { fun newInstance() = Fragment1() } private lateinit var viewModel: SharedViewModel override fun onCreateView(inflater:

Chain Dependant Observables in Resolver

二次信任 提交于 2020-12-13 07:09:54
问题 I have a resolver that needs to fetch data from two dependant Apis before the page is loaded. The second call is defined by the result of the first one, so I try to chain the two observables and need to return the second one at the end of the resolver. Before I tried to chain the observables I had: resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<MySecondObservable> { const observable1 = this.myService.getFirstDataSet(); observable1.subscribe( firstDataSet =>

Synchronous blocking subscribe call to a custom ReplaySubject based observable

[亡魂溺海] 提交于 2020-12-10 06:37:39
问题 The view contains the element: <div *ngIf="showMe">Hello</div> When calling the component method: downloadDemo(): void { this.download$ = this.downloadService.downloadUrlAsBlobWithProgressAndSaveInFile('assets/skypeforlinux-64.deb', 'demo') this.download$.subscribe((download: Download) => { this.showMe = true; console.log('Progress: ' + download.progress); }) } the element shows in the view before all the Progress loggers. And that is how it should be. This HTTP based downloading works just

Synchronous blocking subscribe call to a custom ReplaySubject based observable

丶灬走出姿态 提交于 2020-12-10 06:37:07
问题 The view contains the element: <div *ngIf="showMe">Hello</div> When calling the component method: downloadDemo(): void { this.download$ = this.downloadService.downloadUrlAsBlobWithProgressAndSaveInFile('assets/skypeforlinux-64.deb', 'demo') this.download$.subscribe((download: Download) => { this.showMe = true; console.log('Progress: ' + download.progress); }) } the element shows in the view before all the Progress loggers. And that is how it should be. This HTTP based downloading works just