0

I have this object, and I want to access his properties. If I print the object I get the following outpout:

console.log(Poller)

Object {data: Object}
  data: Object
    response: Object
      clients_id: Array[4]
      customers: Array[4]
      error: false
      notify: Array[4]
      __proto__: Object
    __proto__: Object
  __proto__: Object

but if I run:

console.log(Poller.data)

app.js:177 Object {} // -> empty object

If I run

console.log(Poller.data.response)

undefined

How can I access the clients_id | customers | notify details?

P.S The object is made with this AngularJS service:

factory('Poller', ["$http", "$timeout", "store", "URL", function($http, $timeout, store, URL){
    var notification = {};

    var data = {
        "hairdresser_id": store.get("userId")
    }

    var poller = function(){
        $http.post(URL.url + 'check_for_notifications', data).then(function(res){
            if (res.data.error){
                console.log(res.data.error);
            } else {
                notification.response = res.data;
                console.log(res.data.notify);
            }

            $timeout(poller, 5000);
        });
    }

    poller();

    return {
        data: notification
    };
}]);
ste
  • 3,087
  • 5
  • 38
  • 73
  • 1
    @T.J.Crowder — One of these days I'm going to write a browser extension that counts how many times I close a question as a duplicate of that each day. :) – Quentin Aug 09 '16 at 14:00
  • Seems like you try access data before it was assigned to object (before ajax callback executes) – Maxx Aug 09 '16 at 14:00
  • @Quentin: When you do, be sure to include [this one](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) and [this one](http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) as well... ;-) – T.J. Crowder Aug 09 '16 at 14:02

0 Answers0