2017-02-21 157 views
0

我有一个关于天气预报的迷你应用程序。这是获取气象信息的位置流:刷新指令的缓存

  1. 搜索一个位置

  2. 点击下面的结果就行了。地图将更新并显示标记。

  3. 单击标记,显示天气预报信息的信息框将显示。 我使用指令在地图内生成信息框。这是我的代码:

    app.directive("todayInfoDirective", function ($compile) { return { templateUrl: './src/views/infoBox.html', link: function(scope, element, attrs) { scope.city = scope.$eval(attrs.city); console.log(scope.city); } } });

我试图CONSOLE.LOG这个指令(scope.city)内的数据,我可以看到有每当我点击不同的位置的标记的新数据。

我觉得有一个缓存,它使每个弹出窗口都有相同的内容。 对这个问题有什么想法吗? 这是链接到我的应用程序:beacots.com/wf/index.html

感谢先进的!

回答

0

这是因为我的服务有问题。此前,它看起来像这样:

app.factory('darkSkySvr', function ($http) { 
    var promise = null; 
    return function (lat, lng) { 
     promise = $http({ 
      cache: false, 
      method: 'GET', 
      url: 'http://api.thoitiethanoi.dev2.sutunam.com/forecast/' + lat + ',' + lng, 
     }) 
     return promise; 
    } 
}) 

app.factory('darkSkySvr', function($http) { 
    var promise = null; 
    return function(lat, lng) { 
     if(promise) { 
      return promise; 
     } 
     else { 
      promise = $http({ 
       cache: false, 
       method: 'GET', 
       url: 'http://api.thoitiethanoi.dev2.sutunam.com/forecast/' + lat + ',' + lng, 
      }) 
      return promise; 
     } 
    } 
}) 

我这个代码片段更新