Search code examples
javascriptangulartypescriptonclickvoid

Why using onclick event in angular typescript must give it a void type?


I am trying to call an onclick function in a typescript written in Angular, however, I don't know why this error shows up.

enter image description here

enter image description here

Does anyone know how to solve this type of issue? Please help and give me some suggestion, thanks in advance!


Solution

  • .onclick expects a function and it seems you are assigning it to a result of a function call.

    Try

    element.onclick = redirection;