admin管理员组文章数量:1336148
I'm building a mobile app using ionic 4
and it's two languages ar
and en
, the menu drawer is a pre-built ponent.
So I need to refresh the drawer ponent to get's the right styles based on the dom direction rtl
or ltr
What I'm doing now is just location.reload
reloading the whole app but I don't think that a good approach for doing that
I'm building a mobile app using ionic 4
and it's two languages ar
and en
, the menu drawer is a pre-built ponent.
So I need to refresh the drawer ponent to get's the right styles based on the dom direction rtl
or ltr
What I'm doing now is just location.reload
reloading the whole app but I don't think that a good approach for doing that
4 Answers
Reset to default 5Simplest way to do is to call ngOnInit something like
fn() {
this.ngOnInit();
}
Or try this
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true })
.then(() => {
this.router.navigate(['Your actualComponent']);
});
For Refreshing or re drawing the ponent use the changeDetectionStratergy
so inject the ChangeDetectionRef Service in the ponent where you using the build-in ponent so on any event call the detectChange method for redrawing the ponent.
One of the best method I found is to use NgZone, like this:
import { NgZone } from "@angular/core";
constructor(private ngZone: NgZone) {}
onMyChanges() {
this.ngZone.run(() => {
myChanges...
});
}
Read more here : https://angular.io/api/core/NgZone
call this method whenever you want to reload your page .
that will reload the page
window.location.reload();
本文标签: javascriptHow To refresh an angular componentStack Overflow
版权声明:本文标题:javascript - How To refresh an angular component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742243636a2438992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论