0

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.

4
  • explain your need correctly Commented May 26, 2017 at 5:57
  • cant you call the function again and bind data,,? Commented May 26, 2017 at 6:28
  • You are saving a new data to db through front end only, right? And the code is in the same controller? Commented May 26, 2017 at 6:28
  • yes exactly @SyamPillai Commented May 26, 2017 at 6:41

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.