2014-06-13 43 views
1

我想知道如果我可以在Chrome控制台中运行anguar方法,因为angular方法不是一个globel对象,我不知道如何访问它。 如:我可以在Chrome控制台中运行角度法吗?

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

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

见,我想访问$scope.say(),任何想法?

它和下面一样吗?

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

回答

3

首先,右键单击控制器内部的元素,然后单击inspect element。之后,打开控制台并运行

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

它的工作原理,我可以访问其他控制器的方法吗? –

+0

只要您可以找到控制器内的元素,就可以。 – XrXrXr

相关问题