Using Angularjs $http in browser console

我是研究僧i 提交于 2019-11-29 16:37:16

问题


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();

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.

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?

Update:

It seems like AngularJS 1.0.7 Uncompressed version doesn't work as well. Currently the tested working version is only AngularJS 1.0.7 Minified.

It works for Uncompressed also.


回答1:


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

then

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


来源:https://stackoverflow.com/questions/18436385/using-angularjs-http-in-browser-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!