问题
Before IVY, we could trigger change detection like this, based on this awesome SO answer:
ng.probe(getAllAngularRootElements()[0]).injector.get(ng.coreTokens.ApplicationRef).tick()
The question now is, how do we achieve this in Ivy?
When running in dev mode, and typing ng
in the console reveals this:
But I am unsure how to use this to detect changes in the root element?
workaround
By injecting the ChangeDetectorRef
in a given component, i can do the following (where $0 is the previously selected element in the dev tools):
ng.getComponent($0).changeDetectorRef.detectChanges()
But this is not for the root component?
回答1:
You can call
ng.markDirty($0)
Where $0 is the selected element in the devtools panel.
来源:https://stackoverflow.com/questions/59191406/trigger-change-detection-in-angular-ivy-application