简体   繁体   中英

Push item in array // Angular leaflet

I am new to Angular so I need some help on how can I push an item in the markers.venues .

My code is:

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
                    }
                }
            }
        });

    }]
);

How can I add a new item in the markers.venues in javascript?

eg I tried but didn't work:

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

Angular leaflet is documented here

try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM