Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 数据库值已更新,但在客户端web应用程序中不可见_Angularjs_Http - Fatal编程技术网

Angularjs 数据库值已更新,但在客户端web应用程序中不可见

Angularjs 数据库值已更新,但在客户端web应用程序中不可见,angularjs,http,Angularjs,Http,我有正在工作的angularjs和HTML web应用程序。我面临的问题是,它不会更新服务器中更改的数据。但如果我使用调试器运行它,它会正常工作,并按预期更新数据 例如:脚本文件 $http.get('http://localhost:8080/api/database') .then(function(objectList){ $scope.objectList = objectList.data; }); html文件 <tr ng-repeat="object in ob

我有正在工作的angularjs和HTML web应用程序。我面临的问题是,它不会更新服务器中更改的数据。但如果我使用调试器运行它,它会正常工作,并按预期更新数据

例如:脚本文件

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

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


现在,当我使用
location.path()
routeProvider
将新对象添加到objectList后重新访问页面时,我无法在列表中看到新添加的项,而如果我在browser open的调试器下执行相同的活动,那么我可以在
列表中看到新对象。但是,数据已成功添加到服务器端的数据库。

最佳做法是为所有API请求提供一个someService.js文件,您可以在控制器中使用该服务。此外,您可以全局地将范围变量设置为空数组,然后在解析promise之后,您可以将success.data推入范围变量,它应该可以像一个符咒一样工作

这应该在您的控制器中:

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

如果您在修复过程中遇到困难,请共享一个plunker。

找到了上述问题的解决方案

//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';

使用了您建议的服务文件。但问题是,当我在浏览器中运行应用程序时,浏览器调试器处于打开状态,一切正常,模板的值得到更新,但当浏览器的调试器关闭时,就不会更新,就好像它正在获取页面或http请求的前一个实例,而不是新实例一样。听起来很奇怪。您介意在私有存储库中共享代码吗?在那里我可以深入研究它?