I am trying to print a value in the template of component.
But I am getting the above error
Cannot read property 'name' of undefined
I have removed the extra contents from code for this question. I want to access the first row of the details.
Components file
import {
Component
} from '@angular/core';
import {
Person
} from './person';
import {
getPersonDetailsService
} from './person.service';
@Component({
selector: 'my-app',
template: `
{{data[0].name}}
`
})
export class AppComponent {
data: Person[] = [];
ngOnInit(): void {
this.getPersonDetailsService.getData()
.then(data => this.data = data.slice(1, 5));
}
}