Znowman Znowman - 1 year ago 121
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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download