如何从Angular5组件中访问变量的值?

时间:2018-06-02 15:58:50

标签: typescript angular5

我在角度5中很新,我想从OnMapready()访问llt和llg vlue。我尝试了很多东西,比如将它们设置为服务但是我没有定义。我不能访问/获取编辑的值。所以我如何获得他们买的价值。 我确信有一种简单的方法可以做到这一点,但我似乎无法找到它。这是我的代码



ngOnInit() {
    
    this.llt=this.onMapReady(this.map);
    console.log(this.llt)
  
  }   
   
   
   
   onMapReady(map: any) {
    //toolbar
    var drawnItems = new L.FeatureGroup();
    this.map.addLayer(drawnItems);
    console.log(drawnItems);

    var editableLayers = new L.FeatureGroup();
    map.addLayer(editableLayers);
    var drawPluginOptions = {
      position: 'topleft',
      draw: {
        polyline: {
          shapeOptions: {
            color: '#f357a1',
            weight: 5
          }
        },
        polygon: false
        ,
        circle: {
          metric: 'metric',
          shapeOptions: {
            color: '#662d91'
          }
        },

        rectangle: false,
        marker: {
          iconUrl: 'assets/img/marker.png',
          iconRetinaUrl: 'assets/img/ma.svg',
          shadowUrl: '/marker-shadow.png',
          shapeOptions: {
            color: '#08f'
          }
        }
      },
      edit: {
        featureGroup: drawnItems,
      }
    };
    var drawControl = new L.Control.Draw(drawPluginOptions);
    map.addControl(drawControl);
    map.on('draw:created', function (e) {
      var type = e.layerType ,
      layer = e.layer;
       this.llt = layer.getLatLng().lat;
      console.log(this.llt);
       this.llg = layer.getLatLng().lng;
      console.log(this.llg);
      var coords = e.layer._latlng;
      var tempMarker = drawnItems.addLayer(e.layer);
      //function add dans la base
      var popupContent = ( '<a data-toggle="modal" data-target="#myModel"  ><i class="material-icons" style="cursor:-webkit-grab;font-size: 50px;color:blue">save</i></a>');
      tempMarker.bindPopup(popupContent, {
        keepInView: true,
        closeButton: false
      }).openPopup();    
     
    })
    

    return this.llt,this.llg;
  }
&#13;
&#13;
&#13;

我在这里缺少什么?如何访问变量?我真的需要知道如何处理它。

0 个答案:

没有答案