rxjs

Update several component properties with a single http call using observables

試著忘記壹切 提交于 2019-12-20 04:27:11
问题 Previous post related : Angular2 : Reduce number of Http calls The context is still the same : I'm trying to setup a "dico" component, that need an ID and a Language in input, and should give me some translated Text from my database. dico.component.ts : @Component({ selector: 'dico', template: `{{text}}` // => The text I'm trying to update }) class Dico implements AfterViewInit { // Définition des paramètres et du texte en sortie @Input() private dicoID: string; @Input() private dicoLang:

get new ticket then retry first request

自闭症网瘾萝莉.ら 提交于 2019-12-20 04:07:11
问题 Update: I extend Http class, when I deleteDocument() I want handle error then getTicket() then retry ma request deleteDocument() with new this.TICKET : @Injectable() export class HttpService extends Http { public SERVER_URL: string = 'http://10.0.0.183:8080/alfresco/s/' public TICKET: string = '' constructor(backend: ConnectionBackend, defaultOptions: RequestOptions) { super(backend, defaultOptions); } post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> { return

Angular 4 - rxjs BehaviorSubject usage in Service

南楼画角 提交于 2019-12-20 03:31:11
问题 My Service code looks like below - DataService @Injectable() export class DataService { ... private serviceRequestDtoSource = new BehaviorSubject<ServiceRequestDto>(null); serviceRequestDto$ = this.serviceRequestDtoSource.asObservable(); ... getAccountInfo(serviceRequestDto : ServiceRequestDto){ let body = JSON.stringify(serviceRequestDto); let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); console.log("In data service

Recursive calls to Firestore

拈花ヽ惹草 提交于 2019-12-20 03:02:28
问题 I have a Firebase Firestore with "Components" as a root collection. Each document (a "Component") in the collection may have an array called "children", with each item in the array being an "id" of another component, essentially, a one-to-many relationship. Since every child is also a component it may also have its own children and so forth. Components Collection Parent 1_Parent (document) │ name: 'Parent' │ id: '1_Parent' └─children (array) ├─1.1_Child_one └─1.2_Child_two First Child 1.1

handle cancelled http request in angular httpclient interceptor

时光总嘲笑我的痴心妄想 提交于 2019-12-20 02:56:33
问题 export class AppHttpInterceptor implements HttpInterceptor { private cache = new HttpCache(); private cacheURLList = []; count = 0; constructor(@Inject(AppBlockUiService) private appBlockUiService: AppBlockUiService, @Inject(AppMessageService) private appMessageService: AppMessageService) { } intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const started = Date.now(); this.blockUi(); return next.handle(serverReq) .timeout(720000) .do( event => { if (event

Exception: ObjectUnsubscribedError when working with Observables with RxJS and Angular2

那年仲夏 提交于 2019-12-20 02:07:14
问题 I am still trying to teach myself Angular2 (and I really need to find some better resources) but I have a question. I have moved my data calls to a service and I am using Reactive Subject & BehaviorSubject after instruction from a friend. My calls works, I have a mock REST service from a real back end that gives me a data object (that is an oject of mock user data), my response matches a type I have defined however in my top level app (called App.ts) I have to wait for the response. Now this

Angular unit tests TypeError: this.http.get(…).pipe is not a function

一世执手 提交于 2019-12-20 01:58:08
问题 I'm following this example to make a unit test for service (get request coming from spring app backend) https://angular.io/guide/testing#testing-http-services Service class : @Injectable() export class TarifService { constructor(private messageService: MessageService, private http: HttpClient) { } public getTarifs(): Observable<Tarif[]> { return this.http.get<Tarif[]>(tarifffsURL).pipe( tap(() => {}), catchError(this.handleError('getTarifs', [])) ); } } Unit Test describe('TarifService', () =

Shared RxJS subject for bidirectional data binding in Angular 2

杀马特。学长 韩版系。学妹 提交于 2019-12-20 01:09:55
问题 I have a singleton service for app settings class Setting { get foo() { return storage.get('foo'); } set foo(val) storage.set('foo', val); } } that is bound in components' views as setting.foo . Because storage calls may be costly and because it may be asynchronous, I would prefer to replace getter/setter with RxJS subject that could update and read storage whenever needed. So I'm refactoring it to class Setting { constructor() { this.fooSubject = new ReplaySubject(1); fooSubject.subscribe(

Collect RxJS Observable to Array

守給你的承諾、 提交于 2019-12-19 19:47:40
问题 I'd like to use RxJS to "bridge" async world of events with sync world. Specifically I want to create an function which returns an array of events collected during some time interval. I can create Observable which does what I want var source = Rx.Observable .interval(100 /* ms */) .bufferWithTime(1000).take(1) I can print correct values just fine var subscription = source.subscribe( function (x) { console.log('Next: ' + JSON.stringify(x)); }, function () { console.log('Completed'); }); This

FormControl.detectchanges - why use distinctUntilChanged?

徘徊边缘 提交于 2019-12-19 17:45:16
问题 Reading How to use RxJs distinctUntilChanged? and this, it seems that distinctUntilChanged alters the output stream to only provide distinct contiguous values . I take that to mean that if the same value arrives in immediate succession, you are essentially filtering the stream and only getting one occurrence of that repeated value. So if I write this: this.myFormControl.valueChanges .debounceTime(1000) .distinctUntilChanged() .subscribe(newValue => { console.log('debounced: ', newValue); });