observable

Call a Promise from an Angular HttpInterceptor

旧时模样 提交于 2021-02-16 20:07:38
问题 I've got an angular HttpInterceptor and I need to call an encryption method that's defined like so: private async encrypt(obj: any): Promise<string> { I'm not sure how to handle this in the HttpInterceptor though: intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const modified = req.clone({ body: this.encrypt(req.body) }); return next.handle(modified).pipe( I'm not sure how to tie the two of those together so that I can call the encrypt method properly from

Call a Promise from an Angular HttpInterceptor

£可爱£侵袭症+ 提交于 2021-02-16 20:06:32
问题 I've got an angular HttpInterceptor and I need to call an encryption method that's defined like so: private async encrypt(obj: any): Promise<string> { I'm not sure how to handle this in the HttpInterceptor though: intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const modified = req.clone({ body: this.encrypt(req.body) }); return next.handle(modified).pipe( I'm not sure how to tie the two of those together so that I can call the encrypt method properly from

Call a Promise from an Angular HttpInterceptor

此生再无相见时 提交于 2021-02-16 20:06:20
问题 I've got an angular HttpInterceptor and I need to call an encryption method that's defined like so: private async encrypt(obj: any): Promise<string> { I'm not sure how to handle this in the HttpInterceptor though: intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const modified = req.clone({ body: this.encrypt(req.body) }); return next.handle(modified).pipe( I'm not sure how to tie the two of those together so that I can call the encrypt method properly from

Setting a SwiftUI @EnvironmentObject from outside a view

假如想象 提交于 2021-02-16 13:58:12
问题 I'd like to have a worker task update a SwiftUI view. The worker task is busy doing the procedural work of the application - playing sounds, and firing timer-based events. I'd like to to flash several icons in a SwiftUI view during those timer events. So I want to trigger a view refresh in those icon views. So, I created an environmentObject called Settings. It's instantiated in the App Delegate, and attached to the root view in the SceneDelegate. The Settings object works just fine inside

I'm Trying to get key value pairs from json data via an external api and display it using angular and typescript. How can I achieve this?

痴心易碎 提交于 2021-02-11 14:12:29
问题 I would like to get each key value pair in the results object from my api to display on my front-end. ie(category, type, difficulty, questions correct_answer) I have the service and components set up correctly and all i need to do is fetch the json and display each pair. The method name is called fetchQuestions as seen below. I was able to successfully get data by just simply calling it the same way I did fetchPeople but the json format is not the same so it's not displaying. I then tried

Angular: What's the correct way to return Observable?

萝らか妹 提交于 2021-02-11 13:38:33
问题 I have the following method which isn't working correct: getProducts(): Observable<Product[]> { let PRODUCTS: Product[]; this.http.get(this.base_url + "api/products") .subscribe( (data) => { for(var i in data) { PRODUCTS.push(new Product(data[i].id, data[i].name, data[i].category, data[i].description, data[i].price, data[i].amount)); } }, (error) => { console.log(error); }); return of(PRODUCTS); } The error I'm getting is this: TypeError: Cannot read property 'push' of undefined Now, I know

API polling and timeout

非 Y 不嫁゛ 提交于 2021-02-11 08:52:06
问题 I have a polling use-case where: I want to call an API that, based on business logic, returns numbers(1-10) or error (network issue/ exception in API etc..) instantly (1.5-2 sec). If the API returns an error (network issue/ exception in API etc..) then I want to unsubscribe the polling and display error. If the API returns success, I want to check the return value and un-subscribe(if the return value is 5) or keep the polling going. I want to call API every 5 sec. I want to keep the max time

ngrx get value in function

泪湿孤枕 提交于 2021-02-11 03:33:51
问题 I am unsure if this is the right thinking, but I just started using ngrx for a project and now everything is an observable. It works well when I use the async pipe in the component view, but I am struggeling when I need the value from the store in code. My current approach is to make a property and subscribe in the ngOnInit to the selector, so I can use the current value of the state in my functions. For example storing configration options (webservice address) and then using that inside a

Async pipe with rxjs

走远了吗. 提交于 2021-02-11 01:11:50
问题 I have a little problem in async pipe Here is my case , I need to run nested observables in async pipe in html because i use on push strategy and i dont want to use some workarounds or change detector reference . My problem is , when i run the code below only the first observable is called Should i add return statements? Or whats the problem ? Ts code this.http.getUsers(criteria) .pipe(map(data=>{ data.users.map(user=>{ this.http.getUserData(user.id) .pipe(map(res=>{user.data=res.data}))}}

Reset and Dispose observable subscriber, Reactive Extensions

▼魔方 西西 提交于 2021-02-10 15:50:59
问题 Suppose I have this : public class UploadDicomSet { public UploadDicomSet() { var cachCleanTimer = Observable.Interval(TimeSpan.FromMinutes(2)); cachCleanTimer.Subscribe(CheckUploadSetList); //Start subscriber } void CheckUploadSetList(long interval) { //Stop and dispose subscriber } public void AddDicomFile(SharedLib.DicomFile dicomFile) { //Renew subscriber, call CheckUploadSetList 2 minutes later } } 1- in CheckUploadSetList I want to dispose or finish observable 2- in AddDicomFile I want