小叶AngularFire2代码按钮第一次点击工作1次第二次点击工作2次3次点击工作3次 [英] Leaflet AngularFire2 code in button 1st click works 1 time 2nd click works 2 time 3nd click works 3 time

查看:263
本文介绍了小叶AngularFire2代码按钮第一次点击工作1次第二次点击工作2次3次点击工作3次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    CollectPixi(){

         this.map.locate({setView:true,maxzoom:30}).on("locationfound",e=>{
           this.db.list(`/pixidata`).snapshotChanges().map(actions=>{
             return actions.map(action => {
                     const $key = action.payload.key;
                     const data = { $key, ...action.payload.val() };
                     return data;
                 });
             }).subscribe(items => {

               let pixizaa = items.map(this.getObjectWithoutKnowingKey);

               console.log(pixizaa);
               });




              });
}

CollectPixi函数在按钮中。

CollectPixi function is in button.

当我点击按钮1次时,我得到console.log(pixizaa)输出1次。
如果我点击它第二次我得到输出2次
如果我点击第3次我得到输出3次。

When i click button 1 time i get console.log(pixizaa) output 1 time. if i click it second time i get output 2 times if i click 3rd time i get output 3 times.

html:

  <button ion-button class="button-collectpixi" (click)="CollectPixi()"  block>Collect Pixi!</button>

我点击按钮3次。为什么它不是3

I clicked button 3 times. why its not 3

根据答案

this.map.locate({setView:true,maxzoom:30}).on("locationfound",e=>{

}

是重复的原因。但我需要在collectpixi函数中使用e.latitude e.longitude值.i表示我获取用户位置数据并在collectpixi数据中进行一些计算。

is the reason of repetition.but i need to use e.latitude e.longitude values inside collectpixi function.i mean i take user location data and do some calculations with it inside collectpixi data.

推荐答案

附上 onlocationfound 事件处理程序一次

this.map.on("locationfound",e=>{
  ...
});

每次按下按钮时运行定位

function CollectPixi() {
    this.map.locate({setView:true,maxzoom:30});
}

每次点击都会调用 map.on('locationfound',...)一个按钮。

Do not call map.on('locationfound', ...) every time you click a button.

这篇关于小叶AngularFire2代码按钮第一次点击工作1次第二次点击工作2次3次点击工作3次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆