# Componentes e ciclo de vida (Angular) > Component lifecycle hooks, ngOnInit, ngOnChanges, ngOnDestroy, ngAfterViewInit, component communication, @Input, @Output - 20 perguntas de entrevista - Junior - [Perguntas de entrevista: Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista.md) ## 1. O que é um lifecycle hook em Angular? **Resposta** Um lifecycle hook é um método especial chamado automaticamente pelo Angular em momentos-chave do ciclo de vida de um component ou diretiva. Esses hooks permitem executar código em etapas específicas como criação, atualização ou destruição. Os hooks mais comuns são ngOnInit, ngOnChanges e ngOnDestroy. ## 2. Quando o ngOnInit é chamado? **Resposta** ngOnInit é chamado uma vez após o primeiro ngOnChanges, depois que todas as propriedades @Input foram inicializadas. É o hook ideal para inicializar dados do component, iniciar subscriptions ou chamar serviços. É preferível ao constructor para lógica de inicialização pois todos os bindings estão garantidamente disponíveis. ## 3. Qual é a principal diferença entre ngOnChanges e ngOnInit? **Resposta** ngOnChanges é chamado toda vez que uma propriedade @Input muda de valor e recebe um objeto SimpleChanges contendo valores antigos e novos. ngOnInit é chamado apenas uma vez após a primeira inicialização. Use ngOnChanges para reagir a mudanças de inputs e implementar lógica dependente de valores @Input. Prefira ngOnInit para inicialização única como chamadas API ou configuração inicial. ## Mais 17 perguntas disponiveis - Por que usar ngOnDestroy em um component? - Em que ordem os lifecycle hooks são chamados ao criar um component? Cadastre-se gratis: https://sharpskill.dev/pt/login ## Outros temas de entrevista Angular - [Fundamentos do TypeScript](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/typescript-basics.md): 25 perguntas, Junior - [TypeScript Avançado](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/typescript-advanced.md): 20 perguntas, Junior - [Fundamentos do Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/angular-fundamentals.md): 20 perguntas, Junior - [Services & Dependency Injection](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/services-dependency-injection.md): 20 perguntas, Junior - [Organização de Módulos Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/modules-organization.md): 22 perguntas, Mid-Level - [Angular CLI](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/angular-cli.md): 18 perguntas, Junior - [Diretivas e Pipes](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/directives-pipes.md): 22 perguntas, Mid-Level - [Routing e Navegação](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/routing-navigation.md): 24 perguntas, Mid-Level - [Formulários reativos](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/forms-reactive.md): 26 perguntas, Mid-Level - [Formulários template-driven](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/forms-template-driven.md): 16 perguntas, Mid-Level - [Fundamentos do RxJS](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/rxjs-fundamentals.md): 22 perguntas, Mid-Level - [Operadores RxJS](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/rxjs-operators.md): 24 perguntas, Mid-Level - [HttpClient e chamadas de API](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/http-client.md): 22 perguntas, Mid-Level - [Gerenciamento de estado básico](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/state-management-basics.md): 20 perguntas, Mid-Level - [Change Detection](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/change-detection.md): 20 perguntas, Mid-Level - [Angular Signals](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/angular-signals.md): 20 perguntas, Mid-Level - [Standalone Components](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/standalone-components.md): 18 perguntas, Mid-Level - [Testes unitários em Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/testing-unit.md): 22 perguntas, Mid-Level - [Testes End-to-End](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/testing-e2e.md): 18 perguntas, Mid-Level - [Build e otimização](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/build-optimization.md): 20 perguntas, Mid-Level - [Fundamentos do NgRx](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/ngrx-fundamentals.md): 24 perguntas, Senior - [NgRx avançado](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/ngrx-advanced.md): 24 perguntas, Senior - [Arquitetura Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/angular-architecture.md): 22 perguntas, Senior - [Otimização de desempenho](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/performance-optimization.md): 22 perguntas, Senior - [Segurança e boas práticas](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/security-best-practices.md): 20 perguntas, Senior - [Padrões avançados de RxJS](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/advanced-rxjs-patterns.md): 22 perguntas, Senior - [Angular Universal e SSR](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/angular-universal-ssr.md): 20 perguntas, Senior - [Micro-frontends Angular](https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/micro-frontends-angular.md): 20 perguntas, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/pt/technologies/angular/perguntas-entrevista/components-lifecycle