Last active
March 21, 2022 15:02
-
-
Save lorenzojkrl/95804c16f50017de1916f0e20d6b0b3a to your computer and use it in GitHub Desktop.
Classic pattern
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 { 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