【问题标题】:Angular2 - Supplied parameters do not match any signature of call targetAngular2 - 提供的参数与调用目标的任何签名都不匹配
【发布时间】:2017-08-24 01:40:51
【问题描述】:
import { Component, Input, OnChanges } from '@angular/core';

@Component({
  selector: 'image-display',
  templateUrl: './image-display.component.html'
})
export class ImageDisplayComponent implements OnChanges {
  @Input() image: File;
  @Input() imagePath?: string;

  private fileReader: FileReader;

  constructor() { }

  ngOnChanges() {
    if (this.image && this.fileReader) {
      this.fileReader.readAsDataURL(this.image);
    }
  }
}

在使用 AOT 编译时出现以下错误:

PRINHYLTPAP0592:matata ajays$ ng build --prod --aot
/myApp/src/$$_gendir/app/image-uploader/image-display/image-display.component.ngfactory.ts (61,9): 
Supplied parameters do not match any signature of call target.

【问题讨论】:

  • image-display.component.ngfactory.ts - 这是您显示的文件还是另一个文件?如果是另一个,也请添加那个。此外,您使用此组件的模板。
  • 这里有同样的问题。在 angular 2.4.10 和 cli 1.0 上运行 build prod
  • 我在使用 ng2.4.10 升级到 ng cli 1.0 后也遇到了这个问题
  • @doyevaristo,我实际上遇到了 ngOnChanges() 方法的问题。看看下面,我已经接受了答案。

标签: angular angular2-aot


【解决方案1】:

AOT 强制您通知每个方法调用的每个强制参数。

在您的示例中,方法 ngOnChanges() 实际上应该是 ngOnChanges(changes: SimpleChanges)。

【讨论】:

    【解决方案2】:

    请提供 image-display.component.html 文件的代码。可能是模板上的变量没有初始化到组件上。检查您在模板上使用的所有变量是否存在于 ImageDisplayComponent 上。

    【讨论】:

    • 好答案。我遇到过同样的问题。模板包含带有错误参数的函数调用。
    【解决方案3】:

    如果从 html 调用的方法与组件中的方法定义不匹配,我们会看到此错误。

    主要是调用时传递给方法的参数数量不匹配。

    我在 onModelChange 方法中传递了 $event,它没有在方法定义中声明。

    dropdownChanged(){
      console.log("dropdown changed");
    }
    dropdownChangedActual(evnt:any){
      console.log("dropdown changed");
    }
    <select [(ngModel)]="myModel" (ngModelChange)="dropdownChanged($event)">
         <option>.............</option>
    </select>

    要么声明 $event 或我们传递的任何参数,要么传递方法定义中提到的参数。

    【讨论】:

      猜你喜欢
      • 2017-05-08
      • 2017-11-14
      • 2016-12-07
      • 2018-01-08
      • 2016-11-27
      • 2016-06-09
      • 2017-11-18
      • 2023-03-15
      • 2017-04-28
      相关资源
      最近更新 更多