Skip to content

Instantly share code, notes, and snippets.

@alvarocamillont
Created June 1, 2019 03:41
Embed
What would you like to do?
Exemplo usando SubSink
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