如何从浏览器控制台访问组件控制器?

时间:2016-09-13 19:42:29

标签: javascript angularjs console.log

在angular 1.x中,当使用ng-controller时,可以通过检查元素并调用angular.element($0).controller()从浏览器控制台访问控制器实例。

这不适用于声明为:

的组件
angular.module('foo').component('bar', {
    controller: class {

    }  
});

是否有其他方法可以从控制台访问组件的控制器实例?

2 个答案:

答案 0 :(得分:4)

我们最接近访问组件控制器的似乎是:

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

答案 1 :(得分:0)

作为the manual states

  

controller(name) - 检索当前元素的控制器或   它的父母。默认情况下,检索与之关联的控制器   ngController指令。如果name作为camelCase指令提供   name,然后将检索该指令的控制器(例如   'ngModel')。

2016-09-13 19:37:35: (log.c.164) server started 2016-09-13 19:49:49: (server.c.1558) server stopped by UID = 0 PID = 1 2016-09-13 19:49:50: (log.c.164) server started 2016-09-13 19:49:50: (mod_fastcgi.c.1112) the fastcgi-backend /home/ashley/leagueratings.py failed to start: 2016-09-13 19:49:50: (mod_fastcgi.c.1116) child exited with status 2 /home/ashley/leagueratings.py 2016-09-13 19:49:50: (mod_fastcgi.c.1119) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version. If this is PHP on Gentoo, add 'fastcgi' to the USE flags. 2016-09-13 19:49:50: (mod_fastcgi.c.1406) [ERROR]: spawning fcgi failed. 2016-09-13 19:49:50: (server.c.1022) Configuration of plugins failed. Going down.

对于某个组件,可以缩小到

angular.element($0).controller('bar')

一衬垫。