2017-11-08 12 views
0

할 수있는 어떤 방법입니다 -이 같은재산권 toggleEdit는 "유형의 직원에없는,하지만 나는 직원 구성 요소가 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] 유형에 없습니다. "라는 오류 메시지가 나타납니다. tOn : 거짓; } '.

하지만 방법이 아닙니까? 내가 여기서 뭔가를 놓치고 있니?

+0

export class EmployeeListComponent{ employees: Employee[] = []; AddNewEmployee(){ this.employees.push(new Employee("New Employee", false)); } }

Alexander

답변

1

export class Employee { 
 

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

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

클래스/인터페이스 직원을 표시합니다. 아마도 직원에게 추가하는 객체에 몇 가지 필수 속성이 누락되었을 수 있습니다.
+0

여기 무슨 일이 일어나고 있는지 더 잘 이해할 수있는 링크가 있습니다. https://stackoverflow.com/questions/39433286/method-format-within-angular2-model-class?rq= 1 –

+0

감사합니다. 나는 이미 이것을 알았지 만 Yoni를 확인해 주셔서 감사합니다 !! – Dhanashree