I have the following code:
appModule = angular.module('appModule', []);
appModule.factory('sharedApplication', function($rootScope, $http) {
var sharedApp;
sharedApp = {};
sharedApp.currentView = "home-section";
sharedApp.pastEvents = null;
$http.get('api/highlights').success(function(response) {
return sharedApp.pastEvents = response.data;
});
return sharedApp;
});
This code works perfectly and as expected until I try to minify my javascript and then I get
Error: Unknown provider: eProvider <- e
This is because the $http argument in my factory function has been renamed to 'e' for minification purposes. So how can I manually inform the appModule what to inject by name to avoid minification breaking my code?
Thanks in advance.
Injecting a value into an AngularJS controller function is done simply by adding a parameter with the same name as the value (the first parameter passed to the value() function when the value is defined). Here is an example: var myModule = angular. module("myModule", []); myModule.
Dependency Injection in AngularJS can be defines as the software design pattern which defines the way the software components are dependent on each other. AngularJS provides a set of components that can be injected in the form of dependencies such as factory, value, constant, service, and provider.
The "Application Module" can be injected as a dependency in AngularJS.
Note that you cannot inject "providers" into run blocks. The config method accepts a function, which can be injected with "providers" and "constants" as dependencies. Note that you cannot inject "services" or "values" into configuration.
Try
appModule.factory('sharedApplication', ['$rootScope','$http',function($rootScope, $http) {
}]);
regards
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