Search code examples
angularcompiler-errorsaotangular2-hostbinding

Angular2 host binding issue in AoT compilation


Using the latest Angular2 Webpack Starter (v5.4.1. / Angular 2.4.6) I'm trying to build my code with the AoT compiler. In a custom form input component I have this host binding

@Component({
  selector: 'my-selector',
  templateUrl: 'mycustominput.component.html',
  host: {'(input-blur)': 'onInputBlur($event:any)'},
  providers: [INPUT_VALUE_ACCESSOR]
})

The build run withnpm run build:aot:prod fails with this message

[at-loader] Checking finished with 2 errors
Error in bail mode: [at-loader] compiled/src/app/views/mycustominput.component.ngfactory.ts:142:35 
TS2346: Supplied parameters do not match any signature of call target.

The respective line (142) in the ngfactory is this:

141  if ((eventName == 'input-blur')) {
142    const pd_sub_0:any = ((<any>this.context.onInputBlur($event)) !== false);
143    result = (pd_sub_0 && result);
144  }

Obviously it has something to do with the host binding. No issue with this code in the dev build being JIT-compiled. Any ideas how to fix this?


Solution

  • Oh, my bad. It is just the event parameter missing in the callback method in my component that AoT now complains about.

    changed

    public onInputBlur() {...}   
    

    to

    public onInputBlur(event) {...}