app.controller('MainController', ['$scope','forecast','location',function($scope,forecast,location) {
// this will bring data on page load
forecast.getData(function(data) {
//data bound to scope
$scope.testData = data;
});
//this will bring data on user click
$scope.sendLocation = function(){
//Here is the actual call... just put it on a button click.
location.save(function(successResult){
if(successResult.status === 200){
$scope.$eval( function() {
//data should bound to scope on user click
$scope.testData = successResult.data;
console.log($scope.testData);// successfully log new data to the console
});
};
/* $scope.$apply(); getting $digest already in progress error */
},function(err){
console.log(err);
});
}
}]);
问题是当我点击时,虽然控制台记录了所需的数据,但数据没有在DOM上更新。正如在this帖子中所建议的那样,我在我的处理程序底部使用了$ scope。$ apply()但是得到了错误,我也尝试了$ scope。$ eval和$ timeout,虽然没有给出任何错误但是在同时两者都没有更新模型