Recently delving into the world of AngularJS has been a smooth ride until an unexpected hurdle came my way. Upon loading the page and attempting to utilize a service within a controller, I encountered the following error:
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
My code snippet is as follows:
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();
});
In need of assistance to overcome this issue. Your support is greatly appreciated.