I need to call some Angular controller functions from outside the app. I can't modify the Angular app itself - for sake of simplicity, the code should run in the browser console (the final will be integrated in a Chrome Extension).
I looked at other answers - but they are outdated or simply do not work. AngularJS. How to call controller function from outside of controller component seemed promising, but can't get it to work.
Given the following HTML:
<div data-ng-if="::ctrl.isEntityNotesEnabled"
data-ng-class="{'menu__item--enabled': ctrl.isNotesShown}"
data-ng-click="ctrl.toggleNotesSection()" role="button">
Show
</div>
I want to call ctrl.toggleNotesSection() from JavaScript - but outside of the app.
UPDATE: Some things I tried:
// this will return undefined, old AngularJS approach
angular.element('ng-controller-selector').scope()
// seems a bit closer to what I want, but "ctrl" isn't exposed, nor toggleNotesSection()
angular.element('ng-controller-selector').injector().get('$rootScope')
// I also tried using the DIV element, without success
angular.element('div selector')