Reputation: 141
I have a service in my Angular app called refstorage :
.service('RefStorage',function($window){
var refnum = {}
function set(data) {
refnum = data;
}
function get() {
return refnum;
}
return {
set: set,
get: get
}
})
When i call this from my controller like this :
var refNum = RefStorage.get();
Its returning as [object Object]
, i was expecting a string. Does anyone know why this is?
Upvotes: 0
Views: 29
Reputation: 5792
Because you initialize refnum
as an object:
var refnum = {};
So obviously, if you don't call set()
first, get()
will return an object.
Upvotes: 2