I'm new to Angularjs and everything was going well until I've got this problem.
I'm getting this error as soon as I load the page when I try to use the service inside a controller :
TypeError: Cannot read property 'prototype' of undefined
at Object.instantiate (https://code.angularjs.org/1.3.5/angular.js:4145:82)
at Object.<anonymous> (https://code.angularjs.org/1.3.5/angular.js:4007:24)
>>at Object.invoke (https://code.angularjs.org/1.3.5/angular.js:4138:17)
>>at Object.enforcedReturnValue [as $get] (https://code.angularjs.org/1.3.5/angular.js:3991:37)
>>at Object.invoke (https://code.angularjs.org/1.3.5/angular.js:4138:17)
>>at https://code.angularjs.org/1.3.5/angular.js:3956:37
>>at getService (https://code.angularjs.org/1.3.5/angular.js:4097:39)
>>at Object.invoke (https://code.angularjs.org/1.3.5/angular.js:4129:13)
>>at extend.instance (https://code.angularjs.org/1.3.5/angular.js:8376:21)
>>at https://code.angularjs.org/1.3.5/angular.js:7624:13
This is my code:
var app = angular.module('myApp', []);
app.service('Service'), function () {
var category = { name: 'Test' };
return {
set: function (newObj) {
category.name = newObj;
},
get: function () {
return category;
}
};
};
app.controller('MainController', function (Service, $scope) {
$scope.save = function() {
Service.set($scope.search);
};
$scope.message = Service.get();
});
Please help