3

I'm asking for opinions about my use-case.

very simplified example:

@Input() parentComponent;
childSignal = computed(() => this.parentComponent.parentSignal());

This code will throw runtime error because parentComponent is undefined when signal gets computed for the first time.

Now what would be your way? Initializing signal in ngOnChanges?

CesarD
  • 573
  • 14
  • 30
George Knap
  • 843
  • 9
  • 30

1 Answers1

0

We will eventually get { signal: true } components that have real Signal inputs.

For now (until this feature exists) the simplest approach is to:

  • Create a signal that is updated in ngOnChanges.

    @Input('userId')
    userId: string;
    
    ngOnChanges(changes: SimpleChanges)
    {
       this.userIdSignal.set(this.userId); 
    }
    
    userIdSignal = signal(null);
    
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689