Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing an angular controller from the console (Chrome or Firefox)

I have attached a picture of the click action I want to run from the Chrome console, with various values passed. The button is highlighted in gray top right in the inspect element. It is the savePublish() function I want to learn how to access/use.

enter image description here

The button element is inside a <div ng-controller="ProductEditCtrl as ctrl" .. > container, but of course there are other controller wrappers on the page aliased as ctrl

My question is, how do I access the savePublish() method directly from the Chrome console? And a bonus question-answer would be, how would I load the ProductEditCtrl controller and then call the savePublish method on a different page?

like image 664
Oliver Williams Avatar asked May 07 '17 14:05

Oliver Williams


1 Answers

Try - angular.element($0).scope() to inspect the scope of the button or you can use Chrome extenstion like ng-inspector.

like image 90
Itsik Mauyhas Avatar answered Sep 22 '22 02:09

Itsik Mauyhas