angulartypescriptangular-input

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


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

Solution

  • You want a setter for your input:

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