【问题标题】:Angular2 host binding issue in AoT compilationAoT 编译中的 Angular2 主机绑定问题
【发布时间】:2017-02-21 16:30:53
【问题描述】:

使用最新的Angular2 Webpack Starter (v5.4.1. / Angular 2.4.6) 我正在尝试使用 AoT 编译器构建我的代码。在自定义表单输入组件中,我有这个 host binding

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

使用npm run build:aot:prod 运行的构建失败并显示此消息

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

ngfactory 中的相应行 (142) 是这样的:

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

显然它与主机绑定有关。开发构建中的此代码被 JIT 编译没有问题。任何想法如何解决这个问题?

【问题讨论】:

    标签: angular compiler-errors aot angular2-hostbinding


    【解决方案1】:

    哦,我的错。 AoT 现在抱怨的只是我的组件的回调方法中缺少 event 参数。

    变了

    public onInputBlur() {...}   
    

    public onInputBlur(event) {...}
    

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 1970-01-01
      • 2017-01-22
      • 2017-04-05
      • 2016-05-31
      • 2014-01-22
      • 2017-07-21
      • 1970-01-01
      • 2017-04-15
      相关资源
      最近更新 更多