Angular2 passing function as component input is not working

后端 未结 2 1177
南笙
南笙 2021-01-02 03:42

I\'ve a component that takes function as input. I\'ve passed this function from parent.

Though the function is called, the function is not able to access the depende

2条回答
  •  醉酒成梦
    2021-01-02 03:55

    You need to .bind(this) if you pass methods around:

    
    

    or

    export class App {
      constructor(private service: CustomService) {
      }
      customVal(): string {
        return this.service.getVal();
      }
      customValFn = this.customVal.bind(this);
    }
    

    with

    
    

提交回复
热议问题