Created
June 1, 2019 03:41
-
-
Save alvarocamillont/acb506eda3d9dc188a966d94136dd58b to your computer and use it in GitHub Desktop.
Exemplo usando SubSink
This file contains hidden or 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
import { HttpClient } from '@angular/common/http'; | |
import { Component, OnDestroy, OnInit } from '@angular/core'; | |
import { SubSink } from 'subsink'; | |
import { People, Planet } from '../model/api'; | |
@Component({ | |
selector: 'app-example-subsink', | |
templateUrl: './example-subsink.component.html', | |
styleUrls: ['./example-subsink.component.css'] | |
}) | |
export class ExampleSubsinkComponent implements OnInit, OnDestroy { | |
people: People; | |
planet: Planet; | |
private sub = new SubSink(); | |
constructor(private http: HttpClient) {} | |
ngOnInit() { | |
this.sub.sink = this.http | |
.get<People>('https://swapi.co/api/people/2/') | |
.subscribe((data: People) => { | |
this.people = data; | |
}); | |
this.sub.sink = this.http | |
.get<Planet>('https://swapi.co/api/planets/1/') | |
.subscribe((data: Planet) => { | |
this.planet = data; | |
}); | |
} | |
ngOnDestroy() { | |
this.sub.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment