1
On the corner we have a service called $http
. I know to call it just pass as a parameter of a closure, that the angular does the magic:
angular.module('foo').controller(function ($http) {
/** ... **/
});
And if I want to use the $http
outside the controller
or config
? Has as?
There is a way to use an angular service other than by injecting dependencies into function parameters?
For example:
var $http = ...; // pego a instância do serviço aqui...
$http.get('/pagina-do-site').then(function () {
})
Where exactly do you want to use this? You can cite a practical example?
– celsomtrindade
When I went to make a plugin for Chrome, I had to do this. Use HTTP "out of Angular". I don’t want to depend on
$.ajax
jQuery, but I really needed to use "globally" the$http
. It may be that I got it wrong in my structure, but in Chrome’s "background.js" there was no reason to have oneapp.module
. I really just needed the$http
(not to use jQuery).– Wallace Maxters
I particularly do not know a method of using not only $http, but any other Angular service outside its scope, due to the structural and event "dependencies" it has.
– celsomtrindade
I actually managed to do this using the angular feature itself. I just wanted to know if there was a better way. I got it like this
var $http = angular.injector(["ng"]).get("$http");
– Wallace Maxters
@In this specific case, see: http://pastebin.com/wGCAucTs
– Wallace Maxters
Humm.. Interesting!!! I use this feature nowadays, but in reverse. I make lazyload of some module that is only necessary in a certain view and then make the injection of it INSIDE the angular. But good to know you can make out of it too!
– celsomtrindade
That’s why I denied the answer below. I found very strange the way it was made.
– Wallace Maxters
Let’s go continue this discussion in chat.
– Wallace Maxters