rxjs

Angular 2 Http post error

混江龙づ霸主 提交于 2019-12-11 23:27:55
问题 I have an Ionic 2 app that will get some events from Facebook. I'm trying to send a post request to the Graph Api with a batch containing multiple requests but my subscription always return this error: {"_body":"","status":404,"statusText":"Ok","headers":{"Client-Via", ["shouldInterceptRequest"]},"type":2,"url":"https://graph.facebook.com/"} The subscription inside my component: this.eventListService.get() .subscribe( response => this.response = response, error => this.error = error )

How do I add an item to an Observable<Entity[]> type from an API response, if the Observable is being handled by the async pipe?

隐身守侯 提交于 2019-12-11 18:50:56
问题 So, I have the following service in an Angular 6 codebase: export class GenericService<T> { public endpoint: string; constructor(private http: HttpClient) {} public create(entity: T): Observable<T> { return this.http.post<T>(`${environment.apiUrl}/api/${this.endpoint}`, entity); } } As you can see, the observable create(entity: T) method returns the entity it creates. In the component, it is handled thus: @Component({ selector: 'app-brand-dialog', templateUrl: './brand-dialog.component.html',

Returning an Observable<boolean> from canActivate method and redirect on false

南笙酒味 提交于 2019-12-11 18:05:32
问题 I have been searching for a solution with no luck. I need to call the server if a user is authorized and i need canActivate method to wait for the result for that call. But i can`t seem to put pieces together. Below is my code, my question is in the comments of the code. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { let user: EUser = new EUser(); user.sessionId = localStorage.getItem("sessionId"); //I am not sure how to implement this part. // I

Compare most recent values from multiple BehaviorSubjects

﹥>﹥吖頭↗ 提交于 2019-12-11 17:55:43
问题 Say I have this: isMatchedCountLessThanTotalCountMessage(){ // I want to implement this // "returns" a string asynchronously } getMatchedEventsCount() { return this.dcs.matchCount.asObservable(); } getTotalEventsCount() { return this.dcs.totalCount.asObservable(); } matchedCount and totalCount are like so: public matchCount = new BehaviorSubject<number>(0); public totalCount = new BehaviorSubject<number>(0); these Observables fire integers as values change. Anytime a value is fired from

Observables: Creating a mock http request

点点圈 提交于 2019-12-11 17:45:06
问题 I'm trying to test my front-end code without the back-end api using observables. In my component's template I have a textarea. Ultimately I need to send the textarea content to back-end api using http.post and receive back the validation for the content. In the constructor of my component.ts I define an observable which does some very basic checks and creates mock results after a timeout of 2000ms (like http.post/http.get): private obsVal: Observable < any >; private obsChange: Observable <

How to limit rest calls angular

杀马特。学长 韩版系。学妹 提交于 2019-12-11 17:41:36
问题 I am working on a kanban style drag&drop system with ng2-dragula. And I have an issue, and I think it's because every time you drop an item to a new place it sends the data to the server and redo the whole list of items that you can drag around. And if you do it fast enough you can break the drag&drop cycle. Is there a way to limit the intervall you can make an API call? Similar to RxJS debounceTime, but since the list is almost always changing I cannot pipe a filter to it. Basic constructor

using autocomplete how to filter object on multiple attributes

心不动则不痛 提交于 2019-12-11 17:39:28
问题 I am developing Angular 6 app, I want to iterate over this object. I am new to rxjs, I don't know how to filter object based on multiple attributes, though I tried my best to work something. When I type in name or type it must auto complete and filter the object This is what I have tried but this is not working **template.html** <mat-form-field > <input matInput [matAutocomplete]="auto" [formControl]="customerFilterControl"> <mat-autocomplete #auto="matAutocomplete" [displayWith] = "displayFn

upgrading from angular 4 to 7 causing some problems

风格不统一 提交于 2019-12-11 17:36:41
问题 hey i have upgraded my project from angular 4 to angular 7 and some of the services, modules are deprecated. this is my app.module.ts @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, BrowserAnimationsModule, SharedModule, HttpClientModule, AppRoutingModule, NgbModule.forRoot(), StoreModule.forRoot({}) ], providers: [ SessionTimeoutService, SpinnerService, { provide: HttpClient, useFactory: httpFactory, deps: [XHRBackend, RequestOptions, Store, SpinnerService] }, UtilService

Angular prevent multiple token refresh on asynchronous requests

↘锁芯ラ 提交于 2019-12-11 17:19:12
问题 All my http requests go through the custom HttpService . This service refreshes the token when it's expired before sending the request. It works fine but it refreshes the token multiple times if the loaded page has multiple http requests. For example, if the page has 10 requests through the services, this means 10 times token refresh. I've tried to describe this by sample code: loaded page and used services export class Page1 implements OnInit { constructor( private service1: Service1,

What is the proper way to share data between two components using rxjs ReplaySubject?

£可爱£侵袭症+ 提交于 2019-12-11 17:08:58
问题 I've developed a component with two views. Component A has a contact form, and Component B is the "Thank you" page. Component A: You fill the form and submit it. As soon as the response arrives, a new ReplaySubject value is created. The user will be routed to the component B. Component B: The component is initialized. The component gets the value from the subject. The view is rendered and displays the thank you message. HTTP Call response (Returned after a successful Form data post request):