How to solve a problem of "Cannot set properties of null (setting 'innerHTML')"

914 Views Asked by At

How can I solve a problem of "Cannot set properties of null (setting 'innerHTML')"?

I have an Angular project in which I want to have a unique id for every elements, so I use this code:

Enter image description here

Enter image description here

1

There are 1 best solutions below

3
Aayush Garg On

Are you sure idAct is correct? I am not a daily Angular user, but in HTML it’s just id. Try replacing idAct with id.

Also try using the window.onload event:

window.onload = (event)=>{
       document.getElementById("uniqueID").innerHTML = id()
}