Have you tried to define the variable i in the ts file instead of the html? In that way you'd have it updated whenever you'd need it without having to seek the html element.