In my storage.js
file, I have defined a controller and service as follows:
angular.module('app', []).
controller('storageController', ['$scope', 'storage', function ($scope, storage) {
$scope.loadProducts = function() {
storage.loadProducts();
};
$scope.saveProducts = function(json) {
storage.saveProducts(json);
};
}])
.service('storage', [function() {
this.loadProducts = function loadProducts() {
plugincoredata.loadProducts(function(success) {
alert('SUCCESS: ' + success);
},
function(error) {
alert('ERROR: ' + error);
}
);
};
this.saveProducts = function saveProducts(json) {
bancacoredata.saveProducts(function(success) {
alert('SUCCESS: ' + success);
},
function(error) {
alert('ERROR: ' + error);
},
json
);
};
}]);
Next, in my attempt to create a utils service in a separate file named utils.js
:
angular.module('app', [])
.service('utils', [function() {
var amICordova = null;
this.isCordova = function isCordova() {
if (amICordova == null) {
amICordova = lastIndexOf('http://', 0) !== 0 && lastIndexOf('https://', 0) !== 0;
}
return amICordova;
};
}]);
I want to inject the utils service into the controller so that I can determine if the application is running as a cordova app or in a normal web browser before saving data using native SQLite or IndexedDB. However, when I tried injecting it using
controller('storageController', ['$scope', 'storage', 'utils', function ($scope, storage, 'utils')
, I encountered an error
Error: [$injector:unpr] http://errors.angularjs.org/1.2.28/$injector/unpr?p0=utilsProvider%20%3C-%20utils
How can I successfully inject the utils service into the controller?