angular2-observables

e2e testing angular 7: Failed: Cannot read property 'fetchData' of undefined

假装没事ソ 提交于 2019-11-29 16:22:55
I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode: import { Injectable } from '@angular/core'; import { UrlDecoratorService } from "../../common/url-decorator.service"; import { APIFetcherService } from "../common/api-fetcher.service"; import { Observable } from 'rxjs'; import { IALChrono, ALChrono } from '../../common/IALChrono.interface'; @Injectable() export class AnnonceChronoDetailService { private months: string[]; constructor(private urlDecoratorService: UrlDecoratorService, private apiFetcher: APIFetcherService) { }

Angular 2 Firebase Observable to promise doesn't return anything

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:54:27
问题 I'm currently working on an Angular 2 project with AngularFire2 and I'm trying to convert a FirebaseListObservable to a Promise. I know that it doesn't make much sense since Observables are more useful but this function will be part of another function where multiple promises are chained. And I'm not familiar with how to subscribe to Observables within a chain of promises... The function gets executed in the service, however it seems to not return anything. Basically, what I want to do is

angular - using async pipe on observable<Object> and bind it to local variable in html

筅森魡賤 提交于 2019-11-28 17:29:38
Hi I have a observable user$ with a lot of properties (name, title, address...) component{ user$:Observerable<User>; constructor(private userService:UserService){ this.user$ = this.userService.someMethodReturningObservable$() } } Is there a way to use the async pipe in the html template to subscribe to it and bind it to a local variable like this <div #user="user$ | async"> <h3> {{user.name}} </div> I know can can subscribe to it in the constructor and then unsubscribe in OnLeave/OnDestroy but I was just curious if I could use the async pipe. Cheers # is template reference variable . It defers

Angular2/4 : Refresh Data Realtime

孤者浪人 提交于 2019-11-28 17:19:07
I need to refresh the data in a component page in an interval. Also I need to refresh the data after doing some action. I am using Obeservables in the service so that I can subscribe to when the response is ready. I am pushing the subscriptions to a object so that I can clear that on ngDestroy , I think, I have the following methods to achieve the same. Method 1 : setInterval I have set an interval on ngOnInit , which will call the refreshData in equal interval. The interval object will be cleared using clearInterval in ngOnDestroy method. export class MyComponent implements OnInit, OnDestroy

e2e testing angular 7: Failed: Cannot read property 'fetchData' of undefined

十年热恋 提交于 2019-11-28 11:00:25
问题 I'm trying to do some e2e testing for my service in angular 7, the method return Observable, this is my methode: import { Injectable } from '@angular/core'; import { UrlDecoratorService } from "../../common/url-decorator.service"; import { APIFetcherService } from "../common/api-fetcher.service"; import { Observable } from 'rxjs'; import { IALChrono, ALChrono } from '../../common/IALChrono.interface'; @Injectable() export class AnnonceChronoDetailService { private months: string[];

Angular 2/4 can't read object in initForm()

不打扰是莪最后的温柔 提交于 2019-11-28 10:33:40
问题 I'm creating an edit form in angular and I'm confused about the lifecycle of the object that is returned from my backend server. When I make a call to my service in ngOnInit() , I get workable data. When I assign that to an instance variable, It is undefined in initForm() even though I'm calling initForm() after assigning that data. If you look at the console.log statements you will see that the object works inside the ngOnInit() function but not in initForm() . What am I missing here? How do

How to throw observable error manually in angular2?

Deadly 提交于 2019-11-28 05:17:13
I am working on angular2 app in which I am making a rest call through HTTp as below: login(email, password) { let headers = new Headers(); headers.append('Content-Type', 'application/x-www-form-urlencoded'); let options = new RequestOptions({ headers: headers }); let body = `identity=${email}&password=${password}`; return this.http.post(`${this._configService.getBaseUrl()}/login`, body, options) .map((res: any) => { let response: any = JSON.parse(res._body); if (response.success == 0) { Observable.throw(response); // not working } else if (response.success == 1) { console.log('success');

Observable.forkJoin with a for loop

可紊 提交于 2019-11-28 04:44:36
问题 I am trying to populate an array in my component called processes which is an array of process . Each process also has a list of tasks . So currently, I am working with two api calls which are: /processes and /process/{processId}/tasks I use /processes to get all the processes and initially populate the processes array. Then I use the process id of each process to call the second API to get the tasks of that process. Currently, my code looks something like this: this.processes.forEach(

angular - using async pipe on observable<Object> and bind it to local variable in html

故事扮演 提交于 2019-11-27 10:31:25
问题 Hi I have a observable user$ with a lot of properties (name, title, address...) component{ user$:Observerable<User>; constructor(private userService:UserService){ this.user$ = this.userService.someMethodReturningObservable$() } } Is there a way to use the async pipe in the html template to subscribe to it and bind it to a local variable like this <div #user="user$ | async"> <h3> {{user.name}} </div> I know can can subscribe to it in the constructor and then unsubscribe in OnLeave/OnDestroy

Merge subarrays using Observables

倾然丶 夕夏残阳落幕 提交于 2019-11-27 09:52:52
I have this data structure: [{ id : 1, name : "Item 1", subItems : [{ id : 1, name : "SubItem 1" },{ id : 2, name : "SubItem 2" } ] }, { id : 2, name : "Item 2", subItems : [{ id : 3, name : "SubItem 3" }, { id : 4, name : "SubItem 4" } ] }] I make the following call to a web service to get the items: this.dataService.get("items") Returned is an Observable<Item[]> . What Observable operators can I use to only get a concatenated list of SubItems? I would like to end up with something like this: [{ id : 1, name : "SubItem 1" }, { id : 2, name : "SubItem 2" }, { id : 3, name : "SubItem 3" }, { id