2017-02-21 155 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; 
     } 
    } 
}) 

我這個代碼片段更新