2013-10-15 74 views
0

我是Angular的新手,所以我需要一些幫助,以便如何在markers.venues中推送物品。推送物品//角單張

我的代碼是:

var app = angular.module("basicMapApp", ["leaflet-directive"]); 
app.controller("CenterController", 
    [ '$scope', function($scope) { 
     angular.extend($scope, { 
      defaults: { 
       tileLayer: "https://dnv9my2eseobd.cloudfront.net/v3/foursquare.map-ikj05elx/{z}/{x}/{y}.png", 
       maxZoom: 14, 
       minZoom: 3, 
      }, 
      center: { 
       lat: 52.38, 
       lng: 4.8777, 
       zoom: 6 
      }, 
      markers: { 
       venues: { 
        Madrid: { 
         lat: 52.38, 
         lng: 4.8777, 
         message: "This is Madrid. But you can drag me to another position", 
         focus: false, 
         draggable: true 
        }, 
        Barcelona: { 
         lat: 52.38, 
         lng: 5.8777, 
         message: "This is Barcelona. You can't drag me", 
         focus: false, 
         draggable: false 
        } 
       } 
      } 
     }); 

    }] 
); 

我如何在JavaScript中的markers.venues添加一個新的項目?

例如我試過,但沒有奏效:

$scope.markers.venues.push({ 
    Amsterdam: { 
       lat: 52.38, 
       lng: 5.9777, 
       message: "This is Amsterdam. You can't drag me", 
       focus: false, 
       draggable: false 
       } 
    }); 

角小葉記錄here

+1

'$ scope.markers.venues'不是一個數組,所以推不會工作。試試:'$ scope.markers.venues ['阿姆斯特丹'] = {/*...*/}' – Yoshi

+0

@Yoshi現貨上,感謝結構公告。 – Diolor

回答

0

試試這個

$scope..markers.venues['Amsterdam']={ 
      lat: 52.38, 
      lng: 5.9777, 
      message: "This is Amsterdam. You can't drag me", 
      focus: false, 
      draggable: false 
      } 
+0

謝謝。在'$ scope'之後加一個'.'。 :) – Diolor

+0

WC :)是的,那是錯誤的.. –