Angular pass callback function to child component as @Input similar to AngularJS way

后端 未结 10 1600
庸人自扰
庸人自扰 2020-11-27 10:22

AngularJS has the & parameters where you could pass a callback to a directive (e.g AngularJS way of callbacks. Is it possible to pass a callback as an @Input

10条回答
  •  -上瘾入骨i
    2020-11-27 10:47

    Passing method with argument, using .bind inside template

    @Component({
      ...
      template: '',
      ...
    })
    export class ParentComponent {
      public foo(someParameter: string){
        ...
      }
    }
    
    @Component({...})
    export class ChildComponent{
    
      @Input()
      public action: Function; 
    
      ...
    }
    

提交回复
热议问题