changing element in ngOnInit not working when changing route, but is able to access element

Discussão em 'Angular' iniciado por Agochar Bhatia, Fevereiro 2, 2025.

  1. I have an angular project with a router. In the ngOnInits for the components I want to dynamically set a a p tags value, and an img tags href. It works on inital load, but when i change routes the values dont change. The ngOnInit function is called, but the editing of the two elements does not work.

    document.getElementById('discord-tag').innerHTML = username;
    document.getElementById('profilePicture').setAttribute('src', image_url)


    my code is simple.

    i know the ngOnInit function is working because i put some console.log statements in there to test and they run each time i click on a route link.

    Continue reading...

Compartilhe esta Página