如何在不重新加载页面的情况下刷新 angular 8 中的元素? [英] How to refresh element in angular 8 without page reload?

查看:34
本文介绍了如何在不重新加载页面的情况下刷新 angular 8 中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过单击按钮更新数据库列,我想在单击后更改按钮.如何在不刷新页面的情况下实现这一目标?

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>

推荐答案

完成mark()的处理逻辑后就可以调用ngOnInit()

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

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

另外,请注意尝试路由回同一页面是行不通的,因为 Angular 不会在没有明确告知的情况下将您重新路由到同一页面.

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.

这篇关于如何在不重新加载页面的情况下刷新 angular 8 中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆