Consider this Angular standalone component using type annotations for its input property. What will be rendered in the browser?
import { Component, Input } from '@angular/core'; @Component({ selector: 'app-greet', standalone: true, template: `<p>Hello, {{ name.toUpperCase() }}!</p>` }) export class GreetComponent { @Input() name!: string; }
Think about how Angular initializes inputs and the effect of the ! operator.
The name input is marked with ! which tells TypeScript it will be initialized by Angular. When passed name='world', the template calls toUpperCase() on 'world', rendering 'WORLD'.
In Angular, you want to declare a component property scores as an array of numbers. Which option is syntactically correct?
Remember the TypeScript syntax for arrays.
Option D uses number[] which is the correct way to type an array of numbers. Option D misses the generic type. Option D is a tuple type with one number, not an array. Option D is a number, not an array.
Analyze the following Angular component code. What error will occur when compiling or running it?
import { Component, Input } from '@angular/core'; @Component({ selector: 'app-counter', standalone: true, template: `<p>Count: {{ count }}</p>` }) export class CounterComponent { @Input() count: string = 0; }
Check the type of count and its assigned value.
The property count is typed as string but assigned the number 0. TypeScript will raise an error because the types do not match.
Given this Angular component with a typed property and ngOnInit lifecycle hook, what will be the value of message after initialization?
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-msg', standalone: true, template: `<p>{{ message }}</p>` }) export class MsgComponent implements OnInit { message!: string; ngOnInit() { this.message = 'Hello from ngOnInit'; } }
Consider the effect of the ! operator and when ngOnInit runs.
The ! tells TypeScript the property will be initialized later. Angular calls ngOnInit after construction, setting message. The template then displays the assigned string.
Choose the correct statement about how TypeScript type annotations affect Angular component behavior and compilation.
Think about when TypeScript types are checked versus Angular template rendering.
TypeScript types are used during development to catch errors before running the app. At runtime, Angular does not enforce types; it relies on JavaScript behavior.