Thanks Sander
Main problem is, how to use the data when it had been read?
I have changed the controller in multiple ways but if you look at the cpde
below, it has 2 "this." lines at the end.
.controller('jamboCtrl', function($scope,jamboFactory) {
var myTest= jamboFactory.query(function(data){
console.log(data.thedata); // output: JSON ARRAY!
return data.thedata; // should return JSON ARRAY
});
/*
* multiple lines with great code
*/
this.flotChartData = ChartData;
this.flotBarOptions = barOptions;
});
The 2 variables at the end "this.flotChartData" and "this.flotBarOptions"
canb be used in my view with jamboCtrl.flotChartData and
jamboCtrl.flotBarOptions.
But if i rewrite the code to:
.controller('jamboCtrl', function($scope,jamboFactory) {
var myTest= jamboFactory.query(function(data){
console.log(data.thedata); // output: JSON ARRAY!
return data.thedata; // should return JSON ARRAY
//}); REMOVED THIS
/*
* multiple lines with great code
*/
this.flotChartData = ChartData;
this.flotBarOptions = barOptions;
}); // and PASTED HERE
});
Then all reference to flotChartData, flotBarOptions and myTest is gone in
the view.
Op dinsdag 15 maart 2016 15:56:50 UTC+1 schreef Sander Elias:
>
> Hi Roe,
>
> It's not empty. It is not there yet. That code is executed before the data
> is even being fetched. You can't use data that is not there yet. If you
> must execute code after the data has come in, put it inside your query
> callback function.
>
> and yes, I meant to type $scope.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.