Complete the code to create a standalone Angular component.
import { Component } from '@angular/core'; @Component({ selector: 'app-hello', template: `<h1>Hello, Angular!</h1>`, standalone: [1] }) export class HelloComponent {}
The standalone property must be set to true to make the component standalone in Angular 17+.
Complete the code to inject a service into a standalone component.
import { Component, inject } from '@angular/core'; import { DataService } from './data.service'; @Component({ selector: 'app-data', template: `<p>{{ data }}</p>`, standalone: true }) export class DataComponent { dataService = [1](DataService); data = this.dataService.getData(); }
In Angular 17+, the inject() function is used to get a service instance inside standalone components.
Fix the error in the component template binding.
<template> <h2>[1]</h2> </template> <script setup lang="ts"> import { ref } from 'vue'; const title = ref('Welcome to Angular'); </script>
In Angular templates, you bind directly to the property name without '.value' or function calls. The code is mixing Vue syntax; in Angular, use just {{ title }}.
Fill both blanks to create a component with a signal and display its value.
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', template: `<button (click)="increment()">Count: {{ count() }}</button>`, standalone: true }) export class CounterComponent { count = [1](0); increment() { this.count([2] + 1); } }
The signal function creates a reactive value. To update it, call this.count() with the new value.
Fill all three blanks to create a component that uses a signal and a computed signal.
import { Component, signal, computed } from '@angular/core'; @Component({ selector: 'app-greeting', template: `<p>{{ greeting() }}</p>`, standalone: true }) export class GreetingComponent { name = [1]('Alice'); greeting = [2](() => `Hello, ${this.name()}`); changeName(newName: string) { this.name([3]); } }
Use signal to create reactive state, computed to create derived state, and update the signal by calling it with the new value.