Questions tagged [angular-signals]

Angular signals are a new reactivity primite for Angular. They allow fine-grained reactivity.

30 questions
1
vote
1 answer

Angular computed signal depend on @Input value

I am writing code using Angular 16 Signals. The code will compute a signal that also use Input value. Some of my component works fine but there is a single component that when I inspect, the Input value is still undefined which means that the…
Bharata
  • 685
  • 3
  • 11
  • 23
1
vote
2 answers

Angular effects and conditional use of signals

A concept that illudes me about Angular signals - conditional use of signals inside effects: effect(() => { const count = this.outsideFlag ? this.total() : this.current(); console.log(`The count is: ${count}`); }); Above we make conditional…
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
1
vote
1 answer

Can't set signal from within async piped Observable

When I try setting a signal value from within an Observable that gets piped to async, I get the error: Error: NG0600: Writing to signals is not allowed in a computed or an effect by default. Use allowSignalWrites in the CreateEffectOptions to…
Trevortni
  • 688
  • 8
  • 23
1
vote
1 answer

Why Converting Observable to WritableSignal in Angular 16 throw error of missing properties

I have the following simple code on my component: import {Component, effect, signal, WritableSignal} from '@angular/core'; import {AppService} from "../app.service"; import {toSignal} from "@angular/core/rxjs-interop"; @Component({ selector:…
anown.dev
  • 204
  • 2
  • 10
0
votes
1 answer

Signal update don't call effect

Announcements value in below code changes successfully. effect executes once, but not when changeDates executes. @Injectable({ providedIn: 'platform', }) export class AnnouncementsService { announcements: WritableSignal; …
cooligus
  • 15
  • 6
0
votes
1 answer

Angular Signal Based Components. How do I use signals: true property in component decorator?

I want to try out a signal based component as described here: https://github.com/angular/angular/discussions/49682 I get an error when trying to use signals: true in the component decorator. The error says it is not a know property. I am using the…
Lotus_8
  • 159
  • 2
  • 11
0
votes
1 answer

Is this the right way to use Angular's signals? And why do I still need ChangeDetectorRef.detectChanges()?

I'm trying to use signals and I'm wondering if the use case here is actually benefical from not using Signals and simply have a "normal" class member swiper?: Swiper: @Component({ selector: '[app-test]', standalone: true, imports:…
lampshade
  • 2,470
  • 3
  • 36
  • 74
0
votes
1 answer

What are the alternative to RxJS's operators?

Suppose I have something like this: submit(): void { this.loading = true; dataLength?: number = untracked(this.dataService.data)?.length; this.dataService.addData(this.dataForm.value); effect( () => { if…
noamyg
  • 2,747
  • 1
  • 23
  • 44
0
votes
2 answers

Angular toSignal(toObservable()) does return undefined

Hi assuming following code import { Signal } from '@angular/core'; import { toObservable, toSignal } from '@angular/core/rxjs-interop'; const result = toSignal(toObservable(signal(10))) console.log(result()) // does log undefined instead of 10 I…
Mikelgo
  • 483
  • 4
  • 15
0
votes
1 answer

What is the intended way of using computed signals alongside ngrx selectors and where to put the logic?

I am using Angular 16 and just started with signals. Those make working with ngrx even better. When transitioning I found myself presented with something that can be abstracted to this: const state = { someArray: [1, 5, 7] } export const…
sili3011
  • 9
  • 2
0
votes
1 answer

Is it OK to use a signal as component Input in Angular?

In the following mock-up I use a signal as an input to a component. It works. But I am wondering if this is the proper use of a signal. Seems....weird. The follwing is a service that maintains a list of My Friends: import { Injectable, …
brando
  • 8,215
  • 8
  • 40
  • 59
0
votes
1 answer

When will the effect function for angular signals execute?

Why do these two functions #workingUpdate and #brokenUpdate behave differently? I actually would expect both functions to fail since the ElementRef does not exist while the constructor is called. @Component({ selector: 'test-app', standalone:…
Thomas
  • 3
  • 1
0
votes
1 answer

Is there a way to use Angular Signals outside Angular, in a regular Typescript project?

I'm wondering if there is a way to import just the angular signals in a typescript project, so that I could keep using the same syntax and semantic in other projects, instead of having to install different signals libs..
João Otero
  • 948
  • 1
  • 15
  • 30
0
votes
1 answer

Angular 16 signals side effects

Before signals, I had an observable that I would watch to trigger a FormControl's editable property, like this: this.#isItEditor$ .pipe(takeUntilDestroyed(this.#destroyRef)) .subscribe(x => { const funded =…
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
0
votes
3 answers

Possible to access the old value in Angular 16's effect() function (similar to Vue.js watch)?

In Vue.js, the watch function gets the new and old watched value passed as arguments, which is really helpful in case the differences matter, or when I want to release the previous allocated resource. Now in Angular 16, we finally have signal,…
Peter T.
  • 2,927
  • 5
  • 33
  • 40
1
2