2017-09-19 116 views
0

當我嘗試實例中角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

看那Event類在聲明中

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

,並是指哪一個。它可能與Angular或Javascript的Event類混淆。