Angular - How to fix 'property does not exist on type' error?

后端 未结 5 1609
面向向阳花
面向向阳花 2020-12-29 21:42

I am following this video tutorial (text version of the same). I have followed exactly the same code and I am receiving this error:

error TS2339: Prop

5条回答
  •  -上瘾入骨i
    2020-12-29 22:01

    I would also subscribe to the service method instead of saving it to another value in ngOnInit():

    ngOnInit() {
        this.employees = this._EmployeeService.getEmployees();
    }
    

    To something like:

    ngOnInit(){
       this.getEmployees()
    }
    
    private getEmployees(): void {
        this._EmployeeService.getEmployees()
            .subscribe(fetchedEmployees = > this.employees = fetchedEmployees)
    }
    

提交回复
热议问题