Ryan Yiada
Ryan Yiada

Reputation: 4769

Can I run angular's method in chrome console?

I was wonder if I can run anguar method in chrome console,because the method in angular was not a globel object,I don't know how to access to it. eg:

var app = angular.module('myApp',[]);

app.controller('MainController', function($scope){
  $scope.say = function(){
      alert('hello,world.')
  }
})

See, I want to access the $scope.say() , any idea?

it's the same as below ?

 var fn = function(){
        function test(){
            alert('123')
        }
        return {
            abc: test
        }
    }
    fn().abc();   // 123
    fn().test();  // Uncaught TypeError: undefined is not a function 

Upvotes: 1

Views: 1064

Answers (1)

XrXr
XrXr

Reputation: 2067

First, right click on an element that is inside the controller, then click inspect element. After that, open the console and run

angular.element($0).scope().say()

Upvotes: 3

Related Questions