Last active
March 12, 2019 15:29
-
-
Save yogain123/b19cee2a4a95176a5f05774811a13c3a to your computer and use it in GitHub Desktop.
Angular4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hola |
WE can Complete Observation using complete
completeMe(){
this. totalItems.complete();
}
Create Your Own Observable
import { Observable } from "rxjs/Observable"
// create observable
const simpleObservable = new Observable((observer) => {
// observable execution
observer.next("bla bla bla")
observer.complete()
})
// subscribe to the observable
simpleObservable.subscribe()
// dispose the observable
simpleObservable.unsubscribe()
Main Difference between Observables and Promise
Observables can have multiple values over time
Now if you keep that subscription to the newsletter open, you will get a new one every once and a while. The sender decides when you get it but all you have to do is just wait until it comes straight into your inbox.
If you come from the world of promises this is a key difference as promises always return only one value. Another thing is that observables are cancelable. If you don’t want your newsletter anymore, you unsubscribe. With promises this is different, you can’t cancel a promise
Subscribe to routeQueryParams
https://www.udemy.com/the-complete-angular-master-class/learn/v4/t/lecture/7824574?start=0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Injectable } from '@angular/core';
======
In some component