在浏览器控制台中使用 Angularjs $http [英] Using Angularjs $http in browser console

查看:28
本文介绍了在浏览器控制台中使用 Angularjs $http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了快速验证,我在开发过程中在浏览器控制台中测试了 AngularJS 服务.我将服务注入控制台的方式如这个问题

I've testing AngularJS services in browser console during development for quick verification. The way I inject a service into console is as describe in this question or

var $inj = angular.injector(['myApp']);
var serv = $inj.get('myService');
serv.doSomething();

这与 AngularJS 1.0.7 完美配合.但是,升级到 1.1.5 后,对于使用 $http 服务的服务不再起作用,不会发送 xhr.

That was working perfectly with AngularJS 1.0.7. However, after upgrading to 1.1.5, it doesn't work anymore for services that uses $http service, that no xhr will be sent.

我已经测试过直接注入 $http,它也不起作用.AngularJS 更新日志似乎没有关于这个问题的记录.我可以知道这里有什么问题吗?

I've tested injecting $http directly, it also doesn't work. AngularJS changelog seems to have no record on this issue. May I know what's the problem here?

更新:

似乎 AngularJS 1.0.7 未压缩版本也不能正常工作.目前测试的工作版本只有 AngularJS 1.0.7 Minified.

它也适用于未压缩.

推荐答案

$http = angular.element(document.body).injector().get('$http');

然后

$http.get(...) // or post or whatever

这篇关于在浏览器控制台中使用 Angularjs $http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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