Is there a way I can re render a component manually, say when a user clicks a button??
I've seen similar posts but none of these worked for me for example here
For example,
renderComponent() {
// force component re-render
}
Is there a way I can re render a component manually, say when a user clicks a button??
I've seen similar posts but none of these worked for me for example here
For example,
renderComponent() {
// force component re-render
}
If i understand you properly you are asking about ChangeDetectionStrategy Angular has two options
If you use default it simply will "re-render" you view after each event such a click.
If you are using OnPush, it will re-render if you use observable with | async or you can inject ChangeDetectorRef and "ask" to re-render
But this is true if you are running inside of angular. Sometimes if you are listening to external services and you are running outside of NgZone you need to do ngZone.run
You can use
detectChanges()
ormarkForCheck()
to tell angular to re-render the component again.If you meant to manipulate the view (add, remove or reattach) then here is an example:
live example here
You could trick the router into rendering a fresh copy of current component by temporarily overriding route reuse strategy.. found in some other SO answer :)
in ngOnInit: