Search code examples
angulartypescriptangular-routing

How to refresh element in angular 8 without page reload?


i'm updating database column with a button click, and i want to change the button after click. How can i achieve that without refreshing the page?

Below is my code. and it works fine only if i refresh the page.

    <button *ngIf="solved==1"  class="btn btn-success float-right">Marked</button>
    <button *ngIf="solved==0" (click)="mark()" class="btn btn-warning float-right">Mark </button>

Solution

  • You can call the ngOnInit() once you are done with the processing logic of mark()

    mark() {
      ...
      this.ngOnInit();
    }
    

    Also, note that trying to route back to the same page will not work as Angular will not re-route you to the same page without explicitly telling it to.