当我尝试在 Angular 4 中实例化一个类时,出现此错误:
提供的参数与调用目标的任何签名都不匹配
admin.component.ts:
import { Component } from '@angular/core';
import { Event } from '../event';
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
})
export class AdminComponent {
onSubmit() {
const event = new Event('foo', 'bar');
}
}
event.ts:
export class Event {
constructor(
public event: string,
public comments: string
) { }
}
根据各种 StackOverflow 答案,我尝试了不同的 event.ts
但它产生了相同的错误:
export class Event {
event: string;
readableDate: string;
constructor(public event: string, public readableDate: string) {
this.event = event;
this.readableDate = readableDate;
}
}
最佳答案
查看语句中的Event
类
const event = new Event('foo', 'bar');
以及它指的是哪一个。它可能会与 Angular 或 Javascript 的 Event
类混淆。
关于javascript - Angular 实例化类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46296724/