G.Smith
G.Smith

Reputation: 141

Angular service coming back as Object

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

Answers (1)

fikkatra
fikkatra

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

Related Questions