how to use correctly [ngStyle] with function
问题 I have the following error that constantly returns me the debug console HomeComponent.html:33 ERROR TypeError: Cannot read property 'url' of undefined at HomeComponent.getImageEvent (home.component.ts:73) at Object.eval [as updateDirectives] (HomeComponent.html:33) HomeComponent.html <div [ngStyle]="getImageEvent(i)"> home.component.ts getImageEvent(index: number): object { return {'background-image': 'url(' + this.events[index].images[0].url + ')'}; } 回答1: When you see: Cannot read property