#Angular input signal with assignment and calling service in effect errors?

2 messages · Page 1 of 1 (latest)

spring turret
#

Hello.

i have a component, lets call A, where it it accept as input an object from which is passed into in the html of component B.
in component A i have an input signal called openInput and an effect in the constructor but when i try calling the service using this.bodyVar inside the effect it errors with:
Writing to signals is not allowed in a computed or an effect by default
but im not using any other signals in the effect so i can't be writing to any other signals.
i didn't use compute() instead since i am not computing anything just getting the value from the signal input and passing it to my service.
Maybe i am misunderstanding when to use effect vs compute or somewhere else in my code it is causing a weird error but i don't think that can be the case cause this is the first signal i've used in my codebase?

// component B
<app-component-a [openText]=[bText] />

// component A
  bodyVar: string = ''; 
  openText: OpenInput;
  openInput = input<OpenInput>(null);
  inputViewService: InputViewService = inject(InputViewService);
  myBody$: Observable<InputView>;
  constructor(){
    effect(() => { //Monitoring changes
      console.log(`effect`, openInput ());
      this.openText = openInput();
      this.bodyVar = this.openInput().variable;
      console.log('::constructor in effect:', this.bodyVar);
      this.myBody$ = this.inputViewService.getBody(this.bodyVar);
    });
  }

i wanted to do an http request based on the @input but it appears that i can't do an http request inside effect?

minor spindle
#

This code wouldn't compile. If you want help, post a complete minimal repro as a stackblitz, as explained in #how-to-get-help