I have a base.js
and a services.js in My angular App
but when I move the code to Services.js. The Application Breaks
App.js - This Works
var App = angular.module("App", ["ui.router", "ui.bootstrap", "ngAnimate","toastr"])
.service("utilServices", function ($rootScope, toastr) {
var mem = {};
return {
storeVal: function (key, value) {
mem[key] = value;
},
fetchVal: function (key) {
return mem[key];
},
showAlert: function (msg, msgType, appVal) {
if (msgType === "success") {
return toastr.success(msg, appVal);
}
return false;
}
};
});
App.service("alertService", function (utilServices) {
var appVal = utilServices.fetchVal("vTitle") + " says";
this.Display = function (msg,msgtype) { return utilServices.showAlert(msg,msgtype,appVal); };
return false;
});
App.controller("baseController", window.baseController);
But the same when I move the services to a different file "Services.js"
..........App.js -
var App = angular.module("App", ["ui.router", "ui.bootstrap", "ngAnimate", "toastr"]);
App.service("utilServices", window.commonServices);
App.controller("baseController", window.baseController);
.........Services.js
var mem = {};
window.commonServices = function($rootScope, toastr) {
return {
storeVal: function(key, value) {
mem[key] = value;
},
fetchVal: function(key) {
return mem[key];
},
showAlert: function(msg, msgType, appVal) {
if (msgType === "success") {
return toastr.success(msg, appVal);
}
return false;
}
};
};
window.commonServices.$inject = ["$rootScope", "toastr"];
I get this error in the developer console of My Browser (Chrome) -
TypeError: Cannot read property 'prototype' of undefined
at Object.instantiate (angular.js:4485)
at Object.<anonymous> (angular.js:4346)
at Object.invoke (angular.js:4478)
at Object.enforcedReturnValue [as $get] (angular.js:4330)
at Object.invoke (angular.js:4478)
at angular.js:4295
at getService (angular.js:4437)
at Object.invoke (angular.js:4469)
at extend.instance (angular.js:9136)
at nodeLinkFn (angular.js:8248)
This only occurs when I move the code of service to a separate a file and not when it is declared within the app.js file. I think it has something to do with the $.inject. I'm still a newbie learning the ropes. Any Help would be greatly appreciated :)