yoklainterview sim

Frontend Angular Components Lifecycle Interview Questions

75 verified Frontend Angular Components Lifecycle interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Angular Components LifecycleDifficulty 1
Which decorator marks a TypeScript class as an Angular component?
  • a@Component
  • b@Directive
  • c@Injectable
  • d@NgModule
Explanation:@Component supplies Angular with the metadata needed to treat the class as a component, including its view (template or templateUrl) and, for normal template usage, a selector. @Directive defines a directive without a component view, @Injectable participates in DI compilation, and @NgModule defines a module.
Angular Components LifecycleDifficulty 1
In @Component({ selector: 'app-user-card', ... }), what does the selector property control?
  • aThe component's routing path, used by the Angular Router to match URLs to this component
  • bThe custom HTML tag used to place the component in a template
  • cThe name of the component's exported TypeScript class, as written after the class keyword
  • dThe name of the NgModule (or standalone bundle) that declares and exports the component
Explanation:selector defines the CSS-like selector (by default an element name) that other templates use to instantiate the component, e.g. <app-user-card></app-user-card>. It has nothing to do with routing, the class name, or module membership.
Angular Components LifecycleDifficulty 2
@Component({ selector: 'app-child', template: `{{ name }}` })
class ChildComponent {
  @Input() name!: string;
}

Parent template: <app-child [name]="parentName"></app-child>
What does @Input() on name allow here?
  • aIt lets ChildComponent emit a custom name event upward to whichever parent is listening for it
  • bIt lets ChildComponent inject a name value from a provider registered by the parent's injector
  • cIt lets the parent bind a value into name via property binding
  • dIt makes name automatically stay two-way synced between parent and child with no binding syntax at all
Explanation:@Input() exposes name as a bindable property. The parent uses square-bracket property binding, [name]="parentName", to pass a value down one-way from parent to child.
Angular Components LifecycleDifficulty 1
Which class does Angular provide for a component to emit custom events, typically paired with @Output()?
  • aSubject
  • bBehaviorSubject
  • cObservable
  • dEventEmitter
Explanation:@Output() properties are conventionally typed as new EventEmitter<T>(). Calling .emit(value) on it raises the custom event that a parent template can bind to with (eventName)="...".
Angular Components LifecycleDifficulty 2
@Component({ selector: 'app-child', template: `<button (click)="save()">Save</button>` })
class ChildComponent {
  @Output() saved = new EventEmitter<string>();
  save() { this.saved.emit('done'); }
}

Parent: <app-child (saved)="onSaved($event)"></app-child>
What does $event refer to inside onSaved($event)?
  • aWhatever value was passed to saved.emit(...) — here the string 'done'
  • bThe native DOM MouseEvent object produced by the underlying browser click
  • cA reference to the entire ChildComponent instance that raised the event
  • dThe template reference variable (#) declared on the child element
Explanation:For a custom @Output EventEmitter, $event is exactly whatever value was passed to .emit(...). Only for native DOM events (like a raw (click) on an HTML element) would $event be the browser's Event object.
Angular Components LifecycleDifficulty 2
Which lifecycle hook runs once after Angular has initialized the component's data-bound input properties and is the standard place for initialization logic such as fetching initial data?
  • athe constructor
  • bngOnInit
  • cngAfterViewInit
  • dngOnDestroy
Explanation:ngOnInit runs once after Angular has initialized the component's data-bound input properties. Inputs actually bound by a parent are available then; an optional input that was not bound can still retain its default value or remain undefined. The constructor runs earlier, before Angular applies input bindings.

Test yourself against the 2925-question Frontend bank.

Start interview