我正尝试在浏览器控制台中为此巴士搜索 angualrjs 网站编辑巴士列表。
我试图从控制台访问该页面中的 filteredBusData
(ng-repeat) 列表,该列表在 ng-repeat 中使用。
代码:
方法一:
angular.element(document.body).injector().invoke(function ($rootScope)
{
scope = $rootScope;
console.log(scope.filteredBusData);
});
方法二:
angular.element('[ng-controller="busTicketCheckoutCtrl"]').scope;
`busTicketCheckoutCtrl` is the particular controller
问题:
这两种方法
都不起作用:(
方法一:scope.filteredBusData
未定义
方法二:未捕获错误:[jqLite:nosel] jqLite 不支持通过选择器查找元素!
问题:
如何访问浏览器控制台中的特定 Controller 范围?
任何建议/想法将不胜感激。
最佳答案
@jonnyknowsbest 答案是正确的,但主要是站点已禁用调试信息,您需要先使用 angular.reloadWithDebugInfo()
启用它,此命令将重新加载您的页面。之后您可以访问 Controller 对象。
然后您可以在控制台中访问 Angular 范围。
angular.element(document.querySelector('[data-ng-controller=busTicketCheckoutCtrl]')).scope()
关于javascript - 如何在控制台中获取特定的 Controller 范围列表 - angularjs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30892706/