I cannot access $rootScope inside of a provider.I looked lot of angular other modules implementations. it is the same as how i implemented. What is wrong? it tried urload as a separate function(similar to other getValue function) it did not work
Error is $emit is undefined
define(['angularAMD'], function () {
var contextServiceModule = angular.module('contextService', []);
var contextService = function () {
var context = {};
this.$get = ['$rootScope', function ($rootScope) {
console.log($rootScope);
return function (){
return {
init: init,
getValue: getValue,
setValue: setValue,
urlLoad: function () {
$rootScope.$emit('onInit', {});/// error here
}
};
};
}];
this.init = function () {
return context;
};
this.getValue = function (key) {
var value = context[key] ? context[key] : null;
return value;
};
this.setValue = function (key, value) {
context[key] = value;
};
}
contextServiceModule.provider('contextService', contextService);
});