javascript - Controller not getting $http return data from factory in AngularJS -
been trying code return http return data in $scope.top , use data on page populate element using {{top}}.
all variations i've tried either result in empty $scope.top or $scope.top data arriving late used on page.
latest attempt:
var app = angular.module("it", []); app.factory('dataprovider', function($http){ return { gettop: function(){ return $http.get("db.php"); } } }); app.controller('toplist', function($log, $scope, dataprovider){ $scope.gettop = function(){ var promise = dataprovider.gettop(); promise.then( function(data){ $scope.top = data.data; }, function(errordata){ $log.error('failure loading', errordata); }); } });
what doing wrong?
Comments
Post a Comment