4

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>
Nicholas K
  • 15,148
  • 7
  • 31
  • 57
Invincible me
  • 201
  • 2
  • 5
  • 17

1 Answers1

4

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.

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
  • 1
    Thank you for this. I was stumped because AngularJS seems to do this without it, but wasn't working with Angular. – Jason Feb 03 '22 at 05:41