Skip to content

Instantly share code, notes, and snippets.

@alvarocamillont
Created June 1, 2019 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvarocamillont/acb506eda3d9dc188a966d94136dd58b to your computer and use it in GitHub Desktop.
Save alvarocamillont/acb506eda3d9dc188a966d94136dd58b to your computer and use it in GitHub Desktop.
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