Input suggesstion form not refreshing data when i try to input data directly into database, only when manually doing refresh


#1

Hello, i was trying to implement inside my first app, instead to load new data into JSON object, to input data directly inside a mysql database. So, inside HomeController I introduce addSuggestion function, the input into database is functioning but it is not instantly refreshing on the screen, only when i do manually refresh to the page.

This is the way my HomeController looks like:

app.controller('HomeController',['$scope','$http','get_suggestions',function($scope,$http,get_suggestions){

get_suggestions.success(function(data){
$scope.posts=data;
});

$scope.addSuggestion=function(){
if(!$scope.newsuggest.title || $scope.newsuggest.title===""){
$scope.eroare="Introduceti sugestia";
return;
}else{
$http.post('add_sugestii.php',{'title':$scope.newsuggest.title}).success(function(data,status,headers,config){
$scope.$apply();
})
.error(function(data,status){
$scope.errors.push(status);
});
$scope.newsuggest.title = '';

                                 }
                                 }

}]);