Znowman Znowman - 3 months ago 56
AngularJS Question

Angularjs service not defined

Trying to run a service with my controller.

controllers.controller('test', function($scope, MathService) {
$scope.test = Mathservice.add();

controllers.service('MathService', function(){
this.add = function() {
var a = 1;
var b = 2;
var c = a + b;
return c;

The console says Mathservice not defined. What is wrong here?


Your service is called MathService not Mathservice, notice that javascript is case sensitive so then the word service on MathService must be capitalized like so:

$scope.test = MathService.add();