Accessing the Aurelia viewModel from the browser

If you want to accessing the Aurelia viewModel from the browser console, note that there’s a difference between the element hosting the Aurelia app itself, and an element hosting an Aurelia component. If the app is hosted on the body element (<body aurelia-app="main">) you can use;

document.querySelector('body').aurelia.container.viewModel or
document.querySelector('body').aurelia.root.viewModel

and in the component case, you can find the viewModel via

document.querySelector('my-custom-element').au.controller.viewModel

Leave a Reply

Close Menu