New in angular. I tried to get json response from http get method.
My code
app.factory('getdata', function ($http, $q){
this.getlist = function(){
alert('1');
return $http.get('http://www.w3schools.com/angular/customers.php',{'Access-Control-Allow-Origin': 'localhost:*'})
.then(function(response) {
console.log('response'); console.log(response.data);
alert('2');
return response.data;
});
}
return this;
});
app.controller('streamCtrl', function($scope,getdata, $ionicSlideBoxDelegate, $timeout, $ionicScrollDelegate, $location, $sce){
$scope.trustSrc = function(src) {
return $sce.trustAsResourceUrl(src);
}
getdata.getlist()
.then(function(arrItems){
$scope.sliders = arrItems;
});
alert($scope.sliders);
I get a warning like 1, 'undefined' and 2, but $ scope.sliders data has data. because it worked as soon as I resize the screen, and also can get the correct warning inside
getdata.getlist().then(function(arrItems) {
$scope.sliders = arrItems;
alert($scope.sliders);
});
source
share