Angular, Type 'string' is not assignable to type '(value: any) => void'

461 views Asked by At

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'.
1

There are 1 answers

1
Matthieu Riegler On BEST ANSWER

You want a setter for your input:

  private _foo = ''
  @Input() set foo(value: any) {
    this._foo = value?.toString() || ''
  }