0

I'm passing a value to an @Input() in angular,
but somehow this is not working and I do not understand what I'm doing wrong

<my-component
  [foo]="bar"
></my-component>
  private _foo = ''
  @Input() foo(value: any) {
    this._foo = value?.toString() || ''
  }

Does somebody see my error ?

the error

Type 'string' is not assignable to type '(value: any) => void'.
Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78

1 Answers1

2

You want a setter for your input:

  private _foo = ''
  @Input() set foo(value: any) {
    this._foo = value?.toString() || ''
  }
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134