How do I access the $scope variable in browser's console using AngularJS?

前端 未结 19 1540
渐次进展
渐次进展 2020-11-22 08:35

I would like to access my $scope variable in Chrome\'s JavaScript console. How do I do that?

I can neither see $scope nor the name of my mo

19条回答
  •  無奈伤痛
    2020-11-22 09:02

    Just assign $scope as a global variable. Problem solved.

    app.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
        window.$scope = $scope;
    }
    

    We actually need $scope more often in development than in production.

    Mentioned already by @JasonGoemaat but adding it as a suitable answer to this question.

提交回复
热议问题