import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', standalone: true, template: `<button (click)="count.set(count() + 1)">Clicked {{ count() }} times</button>` }) export class CounterComponent { count = signal(0); }
The component uses Angular's signal to hold a count starting at 0. The template shows a button with the current count. Clicking the button increases the count by 1, updating the displayed text.
Standalone components do not require declaration in a module, so option D is incorrect.
Option C correctly sets standalone: true and includes the template inside the decorator.
Option C misses standalone: true, so it's not standalone.
Option C sets standalone: false, so it's not standalone.
Option C incorrectly places the template as a class property instead of inside the decorator.
import { Component } from '@angular/core'; @Component({ selector: 'app-greet', standalone: true, template: `<h1>{{ greeting }}</h1>` }) export class GreetComponent { greeting: string; constructor() { // Intentionally left blank } }
The 'greeting' property is declared but not initialized, so its value is undefined. Angular renders it as empty text inside the <h1> tag.
No error occurs because Angular tolerates undefined values in interpolation.
Standalone components do not require signals; signals are optional for reactivity.
The 'imports' array is optional unless external modules or components are used.
Option B correctly uses Angular 17+ inject() function to get the service instance as a class property.
Option B uses constructor injection which is valid but not the new inject() function.
Option B manually creates a new service instance, bypassing Angular's DI system.
Option B uses a static property which is not recommended and may cause errors.
Standalone components allow developers to create Angular components without declaring them in NgModules, which simplifies app structure and improves reusability.
Option A is false because standalone components reduce the need for global modules.
Option A is false because signals are optional, not mandatory.
Option A is false because dependency injection remains fully supported.