Angular 从元素获取控制器 [英] Angular Get Controller from Element

查看:34
本文介绍了Angular 从元素获取控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过 Chrome 的控制台找到元素的控制器?我可以通过在 Elements Panel 中选择元素并使用

Is there a way to find the controller for an element through Chrome's console? I can get a reference to the component by selecting the element in the Elements Panel and using

var c = angular.element($0);

c 有一个 controller 属性(看起来像一个构造函数),但我不确定如何处理它.有什么办法可以从这里找到控制器的名字吗?

c has a controller property (looks like a constructor), but I'm not sure what to do with this. Is there any way to find the controller's name from here?

推荐答案

如果你做 angular.element($0).scope() 或者只是 $scope(if您安装了 Batarang Chrome 扩展程序),您应该能够访问所选元素的范围的功能和属性.这还应包括控制器在作用域中公开的任何功能/属性.

If you do angular.element($0).scope() or just $scope(if you installed Batarang Chrome extension), you should be able to get access to selected element's scope's functions and properties. This should also include any functions/attributes that a controller has exposed on the scope.

不过,无法获得控制器的名称.

There is no way to get the controller's name, though.

这篇关于Angular 从元素获取控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆