Cannot read property 'value' of undefined

i had error on : [innerHTML]="[‘value’] , and my coding as below

in page.ts

ngOnInit() {
this.Service.datadetailData$.subscribe((res: any) => {
console (‘check’,this.parsing); ---- console log : [{“data”:[{“columnID”:“0.45”,“value”:“4242”},{“columnID”:“0.398”,“value”:“2”}]}]

in html :
*ngFor=“let datadetail of parsing; let i = index”>

<b [innerHTML]=“[‘value’]”> ===error di console log : core.js:9110 ERROR TypeError: Cannot read property ‘value’ of undefined

tapi kalau cuma

<b [innerHTML]=“datadetail”>

how to troubleshooting for value error ?
thank you for your advice.

Cannot read property ‘value’ of undefined
This means that you are trying to access the value property of something that is undefined, which you are doing a couple of times:

<b [innerHTML]=“[‘value’]”>
So, at the time you are trying to access these values they are not yet defined. An easy way to get around this is just to use the safe navigation operator, i.e:


<b [innerHTML]=“datadetail?.data.value”>
Rather than assuming that datadetail exists, using this syntax will first check if it exists before attempting to access the title property.

1 Like

<b [innerHTML]=“”>
try this

i had been try but still same not had value show it.

Just to get this out of the way, I would strongly urge you to reconsider innerHTML, period. It deliberately doesn’t do much of what people want it to, and it encourages what I would consider unhealthy mixing of presentation and logic. Also, I plead with you to stop using any - it blinds your build tools so they cannot help you, and it makes your code significantly harder to read and maintain.

I also always use and recommend the following options in tsconfig.json, one of which would have caught this problem before you ever had to post this thread:

    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true

Any controller property that is referenced in a template should be initialized to something sane at the point of declaration (if at all possible), or in the controller’s constructor at the very latest. ngOnInit is too late, even if the value wasn’t coming from an asynchronous source.

thank you all, my data is not array but the is string ’ xxx ’ ] after i changed it to array that is working as well.