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>
1
  • 1
    just call the ngOnInit function after you added to the database Commented Jun 22, 2019 at 12:13

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this. I was stumped because AngularJS seems to do this without it, but wasn't working with Angular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.