Angular2 - 'ng build -prod' 提供的结果与调用目标的任何签名都不匹配



我在用什么

我想做什么

  • 运行 ng build -prod 命令

会发生什么

  • 我收到以下错误:

提供的参数与调用目标的任何签名都不匹配。

  • 运行"ng build --watch"时不存在此错误

我尝试过什么

  • 我已经删除了一些 HTML,其中包含一个提交按钮,用于将一些值传递给我的组件打字稿文件中的函数。当我这样做时,构建命令工作正常。

组件网页

下面是导致问题的 HTML 代码段。我正在从输入字段中获取值并将它们推送到函数中。运行"ng build -watch"时,我没有任何问题,一切正常。只有在"prod"命令上,我才会在终端中收到错误

<div class="vs__details__actions">
<button class="vs__button" 
[disabled]="!selectedFiles" 
(click)="submitForm(newTitle.value, newReference.value, newDate.value, newAuditorName.value, newCompanyName.value); newTitle.value=''; 
newReference.value=''; newDate.value=''; newAuditorName.value=''; newCompanyName.value=''"> 
Add 
</button>
</div>

组件打字稿文件

import { Component, OnInit } from '@angular/core';
import { ProjectsAddService } from './projects-add.service';
import { Upload } from './upload';
import * as _ from "lodash";
@Component({
selector: 'upload-form',
templateUrl: './projects-add.component.html',
styleUrls: ['./projects-add.component.css']
})
export class ProjectsAddComponent {
selectedFiles: FileList;
currentUpload: Upload;
constructor(private upSvc: ProjectsAddService) { }
detectFiles(event) {
this.selectedFiles = event.target.files;
}
uploadSingle() {
let file = this.selectedFiles.item(0)
this.currentUpload = new Upload(file);
}
submitForm(title: string, reference: string, date: string, auditorName: string, newCompanyName: string, upload: Upload) {
let file = this.selectedFiles.item(0)
this.currentUpload = new Upload(file);
this.upSvc.submitForm(title, reference, date, auditorName, newCompanyName, this.currentUpload);
}
}

任何帮助将不胜感激:)

使用--prod(生产模式(,angular-cli将使用AoT(提前编译(。

AoT 对类型、签名和其他东西更明智一些。

您的submitForm函数需要一个(非可选的(upload: Upload参数作为最后一个参数,您不会在单击时传递该参数。

这里有两个选项:

第一种(也是建议的(方式:将其设置为可选,如submitForm(title: string, reference: string, date: string, auditorName: string, newCompanyName: string, upload?: Upload)

替代方法:在模板中的最后一个参数处传递null

希望对您有所帮助。


更新:在您编辑问题和评论后,我可能应该在这里添加第三个选项:如果参数未在您的函数中使用,只需删除参数即可。

您的提交表单需要 6 个参数,并且您在模板中使用 5 个值调用该函数。 您缺少"上传"的值。

最新更新