Angular实例化类错误

时间:2017-09-19 09:27:35

标签: javascript angular typescript

当我尝试在Angular 4中实例化一个类时,我收到此错误:

Supplied parameters do not match any signature of call target

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;
    }
}

1 个答案:

答案 0 :(得分:1)

查看语句

中的Event
const event = new Event('foo', 'bar');

以及它指的是哪一个。它可能与Angular或Javascript的Event类混淆。