Angular2 http.get() ,map(), subscribe() and observable pattern – basic understanding

Here is where you went wrong: this.result = http.get(‘friends.json’) .map(response => response.json()) .subscribe(result => this.result =result.json()); it should be: http.get(‘friends.json’) .map(response => response.json()) .subscribe(result => this.result =result); or http.get(‘friends.json’) .subscribe(result => this.result =result.json()); You have made two mistakes: 1- You assigned the observable itself to this.result. When you actually wanted to assign the list of … Read more

Angular – “has no exported member ‘Observable'”

This might be helpful in Angular 6 for more info refer this Document rxjs: Creation methods, types, schedulers and utilities import { Observable, Subject, asapScheduler, pipe, of, from, interval, merge, fromEvent } from ‘rxjs’; rxjs/operators: All pipeable operators: import { map, filter, scan } from ‘rxjs/operators’; rxjs/webSocket: The web socket subject implementation import { webSocket … Read more

take(1) vs first()

Operators first() and take(1) aren’t the same. The first() operator takes an optional predicate function and emits an error notification when no value matched when the source completed. For example this will emit an error: import { EMPTY, range } from ‘rxjs’; import { first, take } from ‘rxjs/operators’; EMPTY.pipe( first(), ).subscribe(console.log, err => console.log(‘Error’, … Read more

‘of’ vs ‘from’ operator

It is important to note the difference between of and from when passing an array-like structure (including strings): Observable.of([1, 2, 3]).subscribe(x => console.log(x)); would print the whole array at once. On the other hand, Observable.from([1, 2, 3]).subscribe(x => console.log(x)); prints the elements 1 by 1. For strings the behaviour is the same, but at character … Read more

Subject vs BehaviorSubject vs ReplaySubject in Angular

It really comes down to behavior and semantics. With a Subject – a subscriber will only get published values that were emitted after the subscription. Ask yourself, is that what you want? Does the subscriber need to know anything about previous values? If not, then you can use this, otherwise choose one of the others. … Read more

Create one-time subscription

Not 100% certain about what you need, but if you only want to observe the first value, then use either first() or take(1): observable.first().subscribe(func); note: .take(1) and .first() both unsubscribe automatically when their condition is met Update from RxJS 5.5+ From comment by Coderer. import { first } from ‘rxjs/operators’ observable .pipe(first()) .subscribe(func); Here’s why

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)