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

Time:01-13

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

CodePudding user response:

You want a setter for your input:

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