Angular에서 여러 훅 사용하기
여러 훅을 동시에 설정할 수 있습니다. 이미 배운 두 가지 훅을 예로 들어 어떻게 하는지 살펴보겠습니다.
두 인터페이스를 임포트합니다:
import { OnInit, OnDestroy } from '@angular/core';
클래스에 연결합니다:
export class UserComponent implements OnInit, OnDestroy {
}
두 개의 훅을 작성합니다:
export class UserComponent implements OnInit, OnDestroy {
constructor() {
console.log('constructor is started');
}
ngOnInit() {
console.log('onInit is applied');
}
ngOnDestroy() {
console.log('onDestroy is applied');
}
}
반응형 조건문 if에서 두 훅의 작동을
확인하세요.
반응형 루프에서 두 훅의 작동을 확인하세요.