Skip to content

Instantly share code, notes, and snippets.

@lorenzojkrl
Last active March 21, 2022 15:02
Show Gist options
  • Save lorenzojkrl/95804c16f50017de1916f0e20d6b0b3a to your computer and use it in GitHub Desktop.
Save lorenzojkrl/95804c16f50017de1916f0e20d6b0b3a to your computer and use it in GitHub Desktop.
Classic pattern
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { TodoService } from './todo.service';
import { ToDo } from './model';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit, OnDestroy {
subscription: Subscription;
data: ToDo;
constructor(private todoService: TodoService) {}
ngOnInit(): void {
this.subscription = this.todoService
.getTodo()
.subscribe((todo) => (this.data = todo));
console.log(this.data);
}
ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment