2017-11-08 8 views
0

何をすべきかの方法、である - このようなプロパティtoggleEditは、「Employee型に欠けているが、それは私が従業員のコンポーネント持っAngular2

export class EmployeeComponent{ 
name:string; 
    isEditOn:boolean; 

    constructor(){} 

    toggleEdit():void{ 
     this.isEditOn = !this.isEditOn; 
    } 
} 

とにEmployeeListコンポーネント -

export class EmployeeListComponent{ 
    employees: Employee[] = []; 

    AddNewEmployee(){ 
     this.employees.push({name:"New Employee", isEditOn:false}); 
    } 
} 

Iを?

プロパティ 'toggleEdit'がタイプ '{name:string; isEdi]に存在しません。新しいEmployeeをリストに追加しようとする行にエラーが発生しています。 tOn:false; } '。

これは方法ではありませんか?私はここに何かを逃していますか

+0

は、クラス/インタフェースの従業員を表示します。おそらく、従業員に追加するオブジェクトに必要なプロパティがいくつか不足している可能性があります。 – Alexander

答えて

1

export class Employee { 
 

 
    constructor(public name: string, public isEditOn: boolean){} 
 

 
    toggleEdit():void{ 
 
     this.isEditOn = !this.isEditOn; 
 
    } 
 
}

export class EmployeeListComponent{ 
 
    employees: Employee[] = []; 
 

 
    AddNewEmployee(){ 
 
     this.employees.push(new Employee("New Employee", false)); 
 
    } 
 
}

+0

ここでは何が起こっているかをよりよく理解するためのリンクです。https://stackoverflow.com/questions/39433286/method-format-within-angular2-model-class?rq= 1 –

+0

ありがとうございます。私はすでにこれを考えましたが、Yoniを確認してくれてありがとう!! – Dhanashree

関連する問題