I am running into an issue injecting a service from an angular js module into my main controller. I am getting this error: https://docs.angularjs.org/error/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-%20solrquery
My code is below:
var app = angular.module('app1',[
'solr'
]);
app.controller('app1cont', ['$scope', 'solrquery', function($scope,solrquery){
console.log("Start");
$scope.value = 1;
solrquery('aaa');
}]);
The solr module looks like this:
var solr1 = angular.module('solr', []);
solr1.run(function(){
console.log("Module Loaded");
});
solr1.service('solrquery',function(a) {
console.log('searching for: ' + a);
}
);
When I run it, I see Module Loaded printed to the console and an error. If I remove the injection from the app.controller and solrquery('aaa'); the code runs fine... Spent several hours on this already, any help would be much appreciated.
Thanks in advance.
EDIT:
Thanks to Anthony for the answer, after re-working the code, the module looks like this:
var solr1 = angular.module('solr', []);
solr1.run(function(){
console.log("Module Loaded");
});
//as a factory
solr1.factory('solrquery',function() {
return function(a) {
console.log('searching for: ' + a);
}
}
);
//as a service
solr1.service('solrser', function() {
this.test = function(a) {
console.log(a);
}
});
And the controller: var app = angular.module('app1',[ 'solr' ]);
app.controller('app1cont', ['$scope', 'solrquery', 'solrser', function($scope,solrquery,solrser){
console.log("Start");
$scope.value = 1;
solrquery('a');
solrser.test('a');
}]);