I want to forget "jQuery" because i like "AngularJS". However, i need to know how to use independent tasks that incorporate AngularJS elsewhere in my application. On this occasion I want to use "$https AngularJS" function to import a JavaScript file for example.
Example (it used to do in jQuery):
$.get("url.js", function(data){ eval(data) }); //ok
console.info($.get); //code code code... ok
Example (as documented in AngularJS)
//In a controller
App.controller('Ctrllr', ['$http', function ($http) {
$http.get("url.js").success(function(data){
eval(data); //ok
});
console.info($http); //code code code.... ok
})
//outside
$http.get("url.js"); //$http is undefined
//How to use $http here?
As you see in the last call, $http is outside of a process. Now, would like to know, how to use the class $http or another Angular utils outside of a controller/application?
The function would be used as so: var $scope = getScope('ctrl'); Now, the above $scope variable is the exact same one that is inside of the "ctrl" controller.
To add or overwrite these defaults, simply add or remove a property from these configuration objects. To add headers for an HTTP method other than POST or PUT, simply add a new object with the lowercased HTTP method name as the key, e.g. $httpProvider. defaults.
$http is an AngularJS service for reading data from remote servers.
Use the HttpClient.get() method to fetch data from a server. The asynchronous method sends an HTTP request, and returns an Observable that emits the requested data when the response is received. The return type varies based on the observe and responseType values that you pass to the call.
Use this:
$http = angular.injector(["ng"]).get("$http");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With