How to access $scope variable in angular from chrome console

后端 未结 4 1852
日久生厌
日久生厌 2021-01-30 20:18

How to access the scope variable widgets from chrome\'s console

function MyCntrl($scope) {
    $scope.widgets = [
        {text:\'Widget #1\', datarow:1, dataco         


        
4条回答
  •  天命终不由人
    2021-01-30 21:01

    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();
    

提交回复
热议问题