Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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 在获取jsonp时,使用promise会在工厂中造成轻微的延迟_Angularjs_Angularjs Routing - Fatal编程技术网

Angularjs 在获取jsonp时,使用promise会在工厂中造成轻微的延迟

Angularjs 在获取jsonp时,使用promise会在工厂中造成轻微的延迟,angularjs,angularjs-routing,Angularjs,Angularjs Routing,所以我一直在学习angularJS,现在我终于遇到了一个令人沮丧的问题。在我的代码中一切都正常,但是内容有一点延迟。页面加载后的延迟大约为0.5秒 工厂代码: app.factory('newsService',['$http', '$q', function($http, $q){ var data = null; return { getNewsList: function() { var promise; promise = $http({

所以我一直在学习angularJS,现在我终于遇到了一个令人沮丧的问题。在我的代码中一切都正常,但是内容有一点延迟。页面加载后的延迟大约为0.5秒

工厂代码:

app.factory('newsService',['$http', '$q', function($http, $q){
  var data = null;
  return {
      getNewsList: function() {
  var promise;
      promise = $http({
        method: 'JSONP',url: 'http://uptsearch.cloudapp.net/solr/rss/select?q=*%3A*',
        params:{'indent': true,
                'wt': 'json',
                'json.wrf': 'JSON_CALLBACK'}
        })
        .then(function(response){
          // cache the response
          data = response;
          return response;
    });

  return promise;
}
} ;
}]);
我的控制器的代码

app.controller('detailedController', function($scope, $stateParams, newsService) {

    $scope.date = $stateParams.index;
    newsService.getNewsList().then(function(news){
    $scope.news = news;
    $scope.date2 = $scope.news.data.response.docs[$stateParams.index].date;
    $scope.title = $scope.news.data.response.docs[$stateParams.index].title;    
})  

});
我还想说,我在一个路由页面上显示内容。也许有什么联系?是什么导致了这次延误


BR的

您正在拨打外部电话以获取一些数据,因此当然会有延迟。很难说到底是什么问题。完全同意w/lucuma,这是一个外部电话,所以不知道需要多长时间,因此承诺。也就是说,您可以在定义路由时使用resolve,以便在切换视图之前加载数据。你可以在这里寻找解决办法:看来我必须提高我的阅读技能。完全错过了该页面的解决部分:/。谢谢但无论如何,我没想到会有这样的延误。