I try to load data from http.get like this:
$http.get("/riddles").success(function(data){
$scope.riddles = data;
$scope.riddlesCount = $scope.riddles.length;
});
And if I call console.log($scope.riddles)
outside this function, $scope.riddles
is undefined, but if I call console.log($scope.riddles)
inside $http.get
, $scope.riddles
is that what I want. I have also a function:
$scope.test = function() {
console.log($scope.riddles);
}
And when I call it using ng-click, when app load, its work correctly.
What am I doing wrong?