Reputation: 115
In my service:
myApp.service('settingsService', [
function() {
var id;
this.setObjectId = function (data)
{
id = data;
}
this.getObjectId = function ()
{
return id;
}
}]);
From my directive: Note: Already injected that service.
settingsService.setObjectId(4); am setting like this
But am getting the following script error:
TypeError: undefined is not a function
If any one knows means please upadte. Thanks in advance
Upvotes: 0
Views: 31
Reputation: 4563
Try to set up your service like this:
myApp.service('settingsService', function() {
var id;
var setObjectId = function(data) {
id = data;
}
var getObjectId = function() {
return id;
}
return {
setObjectId: setObjectId,
getObjectId: getObjectId
};
});
Upvotes: 1