Reputation: 29
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
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
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
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