2015-12-12 34 views
1

一種奇怪的問題/很難找到答案。我相對較新使用angularjs,並有一個我很困惑的問題。谷歌地圖更新爲什麼要更新angularjs scope var?

我建立了一個谷歌地圖,使用http://angular-ui.github.io/angular-google-maps/#!/並有問題。

所以我有一個$ scope.homeBase我在哪裏設置LAT &長爲業主「家庭基地」,我想使用該位置設置負載地圖中心,&引腳以顯示該地點。所以在我心中,酷,設置一個var並在兩個位置使用它。錯誤。

所以這個工作負載,但每次我平移地圖,我想它重新設置地圖中心的位置,然後綁定到地圖標記,併發送標記到屏幕中間,每泛。

反正有沒有兩個沒有約束?或有單獨的變量?沒有他們的約束?

我以爲一個簡單的'var homebase'會刪除綁定,而不會更新var。而不是使用範圍,但它仍然綁定?

這也許是一個新問題,但我感謝任何指向正確的方向。

再次感謝

這是我的代碼。

// uiGmapGoogleMapApi is a promise, The "then" callback function provides a maps object. 
uiGmapGoogleMapApi.then(function() { 

    // Setting homebase coords, these will come from firebase 
    $scope.homeBase = { latitude: -34.18405, longitude: 150.71319 }; 

    // Set default map. 
    $scope.map = { 
     center: $scope.homeBase, 
     pan: true, 
     zoom: 14, 
     events: { 
      click: function(){ 

      } 
     } 
    }; 

    // Set homebase marker. 
    $scope.homebaseMarker = { 
     id: 0, 
     coords: $scope.homeBase, 
     options: { draggable: false }, 
    }; 

}); 

回答

0

我通過

angular.copy(var) 
能夠設置在頁面加載中心