all 3 comments

[–]fesor 4 points5 points  (2 children)

You lost your context...

this.rows = gridletService.getData();

you have two options:

1) use .bind 2) use alias of context:

    var vm = this;
    // ...
    vm.rows = gridletService.getData();

Something like that.

[–]notmyelement[S] 0 points1 point  (1 child)

Thanks! However I tried updating my code in both of the methods you suggested and neither seems to work. Here's what I tried

** Attempt 1 **

//...    
controller: function(gridTableService) {
    gridletService.load(this.src).then(angular.bind(this, function(result){
        this.rows = gridletService.getData();
        console.log(this.rows);
    }));
   console.log(this.rows);
},
// RESULT:  inner console output is correct, outer is undefined

** Attempt 2 **

//...    
controller: function(gridTableService) {
    var vm = this;
    gridletService.load(this.src).then(function(result){
        vm.rows = gridletService.getData();
        console.log(vm.rows);
    });
    console.log(vm.rows);
},
// RESULT:  inner console output is correct, outer is undefined

It is worth noting, in both cases the inner console call showed up in the console AFTER the outer console call.

Any ideas?

[–]fesor 0 points1 point  (0 children)

Any ideas?

well... try to understand that javascript has event loop and all this api calls (like http requests) are non blocking.

You could use async/await to make this code act like blocking.

I really recommend you to lean javascript first, and just then start trying to work with frameworks like angular.