Complete the code to create a standalone Angular component.
import { Component } from '@angular/core'; @Component({ selector: 'app-performance', template: `<p>Performance tuning is important!</p>`, standalone: [1] }) export class PerformanceComponent {}
The standalone property must be set to true to make the component standalone.
Complete the code to inject the ChangeDetectorRef service.
import { Component, ChangeDetectorRef } from '@angular/core'; @Component({ selector: 'app-tune', template: `<p>Change detection example</p>`, standalone: true }) export class TuneComponent { constructor(private [1]: ChangeDetectorRef) {} }
The common variable name for ChangeDetectorRef is cdr, but any valid name works. Here, 'cdr' is the intended name.
Fix the error in the code to properly use the OnPush change detection strategy.
import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'app-fast', template: `<p>Fast change detection</p>`, changeDetection: [1] }) export class FastComponent {}
To enable performance tuning, use ChangeDetectionStrategy.OnPush which tells Angular to check only when inputs change.
Fill both blanks to create a signal and update it in Angular 17+.
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-signal', template: `<button (click)="increment()">Count: {{ count() }}</button>`, standalone: true }) export class SignalComponent { count = [1](0); increment() { this.count([2] + 1); } }
Use signal(0) to create a signal. To update, call this.count(this.count() + 1).
Fill all three blanks to create a memo that doubles the count signal value.
import { Component, signal, computed } from '@angular/core'; @Component({ selector: 'app-memo', template: `<p>Double count: {{ doubleCount() }}</p>`, standalone: true }) export class MemoComponent { count = [1](5); doubleCount = [2](() => this.count() [3] 2); }
Create a signal with signal(5). Use computed to create a memo that multiplies the count by 2.