Znowman Znowman - 10 months ago 98
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?

Answer Source

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();