One of the lesser known abilities of Aurelia is that every Aurelia element has an au
property on it. This means if you query the DOM for an Aurelia element, it will have an au
property which contains app
and controller
.
While this is really handy to know, in most cases if you are a Chrome user, then the Aurelia Context plugin for Chrome is probably a safer bet as it integrates into the Chrome developer tools.
A convenient test of accessing the au
property is to open up Chrome, go into your Aurelia app and then paste the following into the console:
document.querySelector('[au-target-id]').au.controller;
This will allow you to access the underlying view-model via the viewModel
property on the controller as well as numerous other properties. I am not going to go through each property, but this is handy if you’re wanting to access an elements view-model (perhaps from a jQuery plugin, etc) and act accordingly.
The more you know.