Bird
Raised Fist0
Angularframework~20 mins

Signal creation and reading in Angular - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Signal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Angular signal example?
Consider this Angular standalone component using signals. What will be displayed in the browser?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-counter',
  standalone: true,
  template: `<p>Count: {{ count() }}</p>`
})
export class CounterComponent {
  count = signal(5);
}
ACount: 0
BCount: 5
CCount: undefined
DError: signal is not a function
Attempts:
2 left
💡 Hint
Remember that signals hold a value and you read it by calling the signal as a function.
state_output
intermediate
2:00remaining
What is the value of the signal after this code runs?
Given this Angular code snippet, what is the final value of the signal 'name'?
Angular
import { signal } from '@angular/core';

const name = signal('Alice');
name.set('Bob');
name.update(current => current + ' Smith');
A'Bob Smith'
B'Alice Smith'
C'Alice Bob Smith'
D'Bob'
Attempts:
2 left
💡 Hint
The update function receives the current value and returns the new value.
📝 Syntax
advanced
2:00remaining
Which option correctly creates a signal and reads its value?
Choose the code snippet that correctly creates a signal with initial value 10 and reads its value into a variable 'currentValue'.
A
const count = signal(10);
const currentValue = count();
B
const count = new signal(10);
const currentValue = count();
C
const count = signal(10);
const currentValue = count.value;
D
const count = signal = 10;
const currentValue = count;
Attempts:
2 left
💡 Hint
Signals are functions to read their value, not objects with a 'value' property.
🔧 Debug
advanced
2:00remaining
What error does this Angular signal code produce?
Analyze this code snippet. What error will Angular throw when running this?
Angular
import { signal } from '@angular/core';

const count = signal(0);
console.log(count.value);
ASyntaxError: Unexpected token '.'
BReferenceError: signal is not defined
CTypeError: count.value is undefined
DNo error, logs undefined
Attempts:
2 left
💡 Hint
Signals are functions, not objects with a 'value' property.
🧠 Conceptual
expert
3:00remaining
How does Angular's signal system improve component reactivity?
Which statement best explains how Angular signals improve reactivity compared to traditional state management?
ASignals store state in global variables accessible by all components.
BSignals require explicit event listeners to update components on state change.
CSignals automatically track dependencies and update only affected parts without manual subscriptions.
DSignals force full component re-render on any state change regardless of usage.
Attempts:
2 left
💡 Hint
Think about how signals track what uses their value and update selectively.

Practice

(1/5)
1. What does the signal function do in Angular?
easy
A. Registers a service for dependency injection
B. Defines a new Angular component
C. Creates a reactive value that can be read and updated
D. Starts an HTTP request

Solution

  1. Step 1: Understand the purpose of signal

    The signal function is used to create reactive values that Angular tracks for changes.
  2. Step 2: Identify what signal does

    It creates a value container that can be read by calling it and updated to trigger UI changes.
  3. Final Answer:

    Creates a reactive value that can be read and updated -> Option C
  4. Quick Check:

    Signal creation = reactive value container [OK]
Hint: Remember: signal() creates reactive values you can read and update [OK]
Common Mistakes:
  • Confusing signal with component or service creation
  • Thinking signal starts HTTP requests
  • Assuming signal is for styling or templates
2. Which of the following is the correct way to create a signal with initial value 10?
easy
A. const count = signal(10);
B. const count = Signal(10);
C. const count = signal = 10;
D. const count = signal.create(10);

Solution

  1. Step 1: Check the correct syntax for signal creation

    The correct syntax uses lowercase signal as a function with the initial value in parentheses.
  2. Step 2: Compare options

    const count = signal(10); matches the correct syntax: const count = signal(10);. Others use wrong casing or invalid syntax.
  3. Final Answer:

    const count = signal(10); -> Option A
  4. Quick Check:

    signal() function call with initial value [OK]
Hint: Use lowercase signal() with parentheses for initial value [OK]
Common Mistakes:
  • Using uppercase Signal instead of signal
  • Assigning signal = 10 instead of calling signal(10)
  • Trying to call a create method on signal
3. Given this code:
const count = signal(5);
console.log(count());
count.set(10);
console.log(count());

What will be printed in the console?
medium
A. 5 then 10
B. 5 then 5
C. 10 then 10
D. Error because set() is not a function

Solution

  1. Step 1: Read the initial signal value

    The signal count is created with initial value 5, so count() returns 5.
  2. Step 2: Update the signal and read again

    Calling count.set(10) updates the value to 10, so the next count() returns 10.
  3. Final Answer:

    5 then 10 -> Option A
  4. Quick Check:

    Signal read before and after set() = 5, 10 [OK]
Hint: Remember: signal() reads, set() updates value [OK]
Common Mistakes:
  • Thinking count() returns the same value after set()
  • Assuming set() is not a valid method
  • Confusing signal reading with direct variable access
4. Identify the error in this code snippet:
const name = signal('Alice');
console.log(name);
name('Bob');
medium
A. Cannot call signal variable as a function
B. Missing parentheses when reading signal value
C. Cannot assign new value by calling signal as function
D. Signal must be updated using name.set('Bob')

Solution

  1. Step 1: Check how signal values are read and updated

    Signals are read by calling them as functions: name(). To update, use name.set(newValue).
  2. Step 2: Identify the error in updating

    The code tries to update the signal by calling name('Bob'), which is invalid. The correct way is name.set('Bob').
  3. Final Answer:

    Signal must be updated using name.set('Bob') -> Option D
  4. Quick Check:

    Update signals with set() method [OK]
Hint: Use set() to update signals, not calling them as functions [OK]
Common Mistakes:
  • Trying to update signal by calling it as a function
  • Forgetting parentheses when reading signal value
  • Confusing signal with normal variables
5. You want to create a signal that holds a list of numbers and update it by adding a new number. Which code correctly updates the signal to add 4 to the list?
const numbers = signal([1, 2, 3]);
// Add 4 to numbers here
hard
A. numbers([...numbers(), 4]);
B. numbers.set([...numbers(), 4]);
C. numbers.value.push(4);
D. numbers = [...numbers(), 4];

Solution

  1. Step 1: Understand how to read and update signals

    Read the current value by calling numbers(). To update, use numbers.set(newValue).
  2. Step 2: Add 4 to the existing array immutably

    Create a new array with existing values plus 4: [...numbers(), 4]. Then update signal with numbers.set([...numbers(), 4]).
  3. Final Answer:

    numbers.set([...numbers(), 4]); -> Option B
  4. Quick Check:

    Update signal immutably with set([...signal(), newItem]) [OK]
Hint: Use set() with new array copy to update list signals [OK]
Common Mistakes:
  • Trying to call signal as a function to update
  • Mutating array directly without set()
  • Assigning new array to signal variable directly