i have popular error, TypeError: Cannot read property 'something' of undefined. and my code works
But why i should to use *ngIf or async? why it happens?
and can i solve this problem without this strange solutions what i describe bellow
Sorry but i can not find answer why
// service
public getEmployee(id) {
return this._af.database.object(`/employee/${id}`)
.map(response => response)
.catch(error => Observable.throw(error.json()));
}
//component
public employee: Employee;
ngOnInit() {
this.route.params
.switchMap((params: Params) => this._EmployeesService.getEmployee(params['employeeId']))
.subscribe(employee => {
this.employee = employee;
});
}
//html
<div *ngIf="employee">...</div>` // ok
<div>{{employee?.name}}</div> // also ok
<div>{{employee.name}}</div> // error here, TypeError: Cannot read property 'name' of undefined.