Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS change variable with console

I'm learning Angular and I made a simple game, I'm using ng-inspector to view current variable value, but how can I cahange variable value with browser console?

like image 537
opengl Avatar asked Dec 19 '22 03:12

opengl


1 Answers

You may access a controller's scope in the console by:

  1. Select the node in the elements tab by clicking on it.
  2. Execute var scope = angular.element($0).scope();

$0 is a reference to the selected DOM element in the console (webkit).

If instead you want access to factory/service variables you may use the injector method:

var injector = angular.element($0).injector();

var srv = injector.get('serviceName');
like image 61
chris Avatar answered Dec 24 '22 01:12

chris