how to access $scope variable in angular from chrome console

how to access the scope variable widgets from chrome's console

function MyCntrl($scope) {
      $scope.widgets = [
                  {text:'Widget #1', datarow:1, datacol:1, datasizex:3, datasizey:3},
                  {text:'Widget #2', datarow:2, datacol:1, datasizex:3, datasizey:3},
                  {text:'Widget #3', datarow:1, datacol:2, datasizex:3, datasizey:3},
                  {text:'Widget #4', datarow:2, datacol:2, datasizex:3, datasizey:3}
      ];

something like $scope.widgets simply doesnt work in the console!

The scope is bound to the DOM so you need to grab an element and use some angular code to get the scope.

Your best bet is to get an element that the Controller is bound to and have a look at the scope on that.

Here is the answer how to access the angular $scope variable in browsers console

You can either follow the asnwer of Will or install Angular Batarang Chrome extension. This will not only allow you to view and manipulate '$scope' object from, let's say your JavaScript console, but also it's a fundamental tool when developing complex AngularJS apps.

this is a way of getting at scope without batarang. Assuming you have references to jquery and angular on your page, you can do:

var scope = angular.element($('#selectorId')).scope();

or if you want to find your scope by controller name, do this:

var scope = angular.element($('[ng-controller=myController]')).scope();

After you make changes to your model, you'll need to apply the changes to the DOM by calling

scope.$apply();