Namburi Akhil
Namburi Akhil

Reputation: 29

ajax reload in angular js

I have dropdown which generates items from json.

`generalService.getUrlData('get_data')
        .then(function(data){
            $scope.names = data.data;
            for (var i=0; i < $scope.names.length; i++) {
                var compn = $scope.names[i].NAME;   
                $scope.compname.push(compn);
            }
    });`

my question is when i entered a new data to db using typeahed combo box the newly entered data is not populating in the dropdown. It is populating after the page is reloaded. How to reload the ajax call when submit button is clicked, so that the newly entered item appears in dropdown without reloading the page.I hope you understood my question.

Upvotes: 0

Views: 878

Answers (3)

Manikandan Velayutham
Manikandan Velayutham

Reputation: 2228

When you entered a new data to db using typeahed combo box. You need to trigger again dropdown getdata api. or use $route.reload() after new data to db by typeahed combo box but, It will call all on-fly functions requests.

Upvotes: 0

Syam Pillai
Syam Pillai

Reputation: 5217

Call the getUrlData once the save new data API call is success.

Eg:

function getAllUrlData () {
  generalService.getUrlData('get_data')
    .then(function(data){
        $scope.names = data.data;
        for (var i=0; i < $scope.names.length; i++) {
            var compn = $scope.names[i].NAME;   
            $scope.compname.push(compn);
        }
  });
}

function save newData (new_data) {
   generalService.veNewasUrlData('get_data')
    .then(function(data){
       getAllUrlData()   // fecth all data again when save data is success
    });
}

OR

Don't call the getAllUrlData function again. Just push the new data to $scope.compname when you are saving the new data.

$scope.compname.push(newData) // this will automatically come once reload. So no issues with temporary push

Upvotes: 0

Andrey Ponteleev
Andrey Ponteleev

Reputation: 11

you need to invoke new http request if you want to load new data from server to client.

if your data just entered from consumer, you can avoid new request by simulating serverside update

Upvotes: 1

Related Questions