數據庫值已更新,但在客戶端角度Web應用程序中不可見

[英]Database values updated but not visible in the client side angular web application


I have working angularjs and HTML web application. The problem that I am facing is that it doesn't updates the data changed in the server. But if I run it with debugger it works fine and updates the data as expected.

我有工作angularjs和HTML Web應用程序。我面臨的問題是它不會更新服務器中更改的數據。但是,如果我使用調試器運行它,它可以正常工作並按預期更新數據。

For example: script file

例如:腳本文件

 $http.get('http://localhost:8080/api/database')
.then(function(objectList){
    $scope.objectList = objectList.data;
});

html file

<tr ng-repeat="object in objectList">

now when I revisit the page after adding new object to the objectList using location.path() and routeProvider the I can't see the newly added item in the list while if I perform the same activity with the debugger of browser open then I can see the new object in the List. However the data is added to the database at server side successfully.

現在,當我使用location.path()和routeProvider將新對象添加到objectList后重新訪問頁面時,我無法在列表中看到新添加的項目,而如果我使用瀏覽器的調試器執行相同的活動,那么我可以查看列表中的新對象。但是,數據將成功添加到服務器端的數據庫中。

2 个解决方案

#1


0  

The best practice would be to have a someService.js file for all the API requests and you can use that service in your controller. Moreover, you can set the scope variable as an empty array globally and then after resolving the promise you can push the success.data into the scope variable and it should work like a charm.

最佳做法是為所有API請求提供someService.js文件,您可以在控制器中使用該服務。此外,您可以將范圍變量全局設置為空數組,然后在解析promise之后,您可以將success.data推送到范圍變量中,它應該像魅力一樣工作。

This should be in your controller:

這應該在你的控制器中:

$scope.objectList = [];
var databasePromise = someservice.getDatabase();
databasePromise.then(function(success) {
   $scope.objectList = success.data;
}, function(failure) {
   console.log(failure);
});

Please share a plunker, if you are having a hard time fixing it.

如果你很難修理它,請分享一個plunker。

#2


0  

FOund the Solution to above question.

找出上述問題的解決方案。

//initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};    
    }    

    // Answer edited to include suggestions from comments
    // because previous version of code introduced browser-related errors

    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
    // extra
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/06/01/72580618fc1f602909fb3fadfdceaa4e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com