【问题标题】:Angular2 ng build --prod error Supplied parameters do not match any signature of call targetAngular2 ng build --prod error 提供的参数与调用目标的任何签名都不匹配
【发布时间】:2023-03-15 15:57:01
【问题描述】:

我刚开始使用 Angular2,这是我的第一个项目。
https://github.com/Exlord/angular2-sample-dynamicform

这在开发中运行良好,但当我尝试 ng build --prod 时,我收到此错误:ERROR in ng:///E:/www/ng2-sample/src/app/field/field-form/field-form.component.html (2,26): Supplied parameters do not match any signature of call target.

错误是指this line

<div class="form-group" [ngClass]="{'has-error':!form.get('name').valid && form.get('name').touched}">

我几天前安装了 angular2+cli,所以我认为一切都是最新的。

我错过了什么?这是什么意思?

【问题讨论】:

    标签: angular build


    【解决方案1】:

    这里有错误

    if (('ngSubmit' === en)) {
      const pd_2:any = ((<any>_co.save(_co.form.value,_co.form.valid)) !== false); <= this line
      ad = (pd_2 && ad);
    }
    

    来自

    <form [formGroup]="form" (ngSubmit)="save(form.value, form.valid)" novalidate>
    

    如果您打开 field-form.component.ts 文件

    save(value: any): void {
      this.submitted = true;
      this.fieldService.save(<Field>value).then((field) => {
        this.submitted = false;
        this.form.reset();
        this.onSave.emit();
      });
    }
    

    您可以注意到save 方法只有一个参数,而您在模板中传递了两个参数

    【讨论】:

      【解决方案2】:

      尝试在组件提供商处添加 FormBuilder 和 FieldService。

      @Component({
        selector: 'app-field-form',
        templateUrl: './field-form.component.html',
        styleUrls: ['./field-form.component.css'],
        providers : [FormBuilder, FieldService]
      })
      

      【讨论】:

        猜你喜欢
        • 2018-01-18
        • 2017-09-02
        • 1970-01-01
        • 2017-08-24
        • 2017-05-08
        • 2017-11-14
        • 2016-12-07
        • 2018-01-08
        • 2016-11-27
        相关资源
        最近更新 更多