Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何像全局变量一样从方法将数据插入arrayList_Javascript_Angular - Fatal编程技术网

Javascript 如何像全局变量一样从方法将数据插入arrayList

Javascript 如何像全局变量一样从方法将数据插入arrayList,javascript,angular,Javascript,Angular,我需要将数据从数据库插入到ArrayList,以后需要使用它,但我无法直接创建它。那我怎么办 ngOnInit() { var result_array = []; this.get_All_Col_data(myfrugalmap,result_array,Marker_array); } get_All_Col_data(map,collection_array,markers){ const myIcon_Col = L.icon({ ic

我需要将数据从数据库插入到
ArrayList
,以后需要使用它,但我无法直接创建它。那我怎么办

ngOnInit() { 
var result_array = [];
    this.get_All_Col_data(myfrugalmap,result_array,Marker_array);
    }    

 get_All_Col_data(map,collection_array,markers){
    const myIcon_Col = L.icon({
      iconUrl: 'https://img.icons8.com/ultraviolet/40/000000/collect.png'
    });
    const myIcon_vente = L.icon({
      iconUrl: 'https://img.icons8.com/color/50/000000/low-price-euro.png'
    });
    this.CollectionService.getallCollections().subscribe((data: Collection_info[]) =>{
      this.Collection_info = data;
      for(var i =0; i<this.Collection_info.length;i++){
        console.log("name :" + this.Collection_info[i].emailcol);
        console.log("type :" + this.Collection_info[i].type);
        if(this.Collection_info[i].type==='collection'){
             var m = L.marker([Number(this.Collection_info[i].lat_col), Number(this.Collection_info[i].long_col)], {icon: myIcon_Col}).addTo(map);
                 m.bindPopup("Collection pt " + this.Collection_info[i].nom_col);
                 markers.push(m);
                 collection_array.push(this.Collection_info[i]);

            }else{
          var m = L.marker([Number(this.Collection_info[i].lat_col), Number(this.Collection_info[i].long_col)], {icon: myIcon_vente}).addTo(map);
          m.bindPopup("Collection vente " + this.Collection_info[i].nom_col);
          collection_array.push(this.Collection_info[i]);
          markers.push(m);
        }
      }
      console.log(collection_array)
      return collection_array;
     });
ngOnInit(){
var结果_数组=[];
获取所有列数据(myfrugalmap、结果数组、标记数组);
}    
获取所有列数据(地图、集合数组、标记){
常量myIcon\u Col=L.icon({
伊克努尔:'https://img.icons8.com/ultraviolet/40/000000/collect.png'
});
常数myIcon\u vente=L.icon({
伊克努尔:'https://img.icons8.com/color/50/000000/low-price-euro.png'
});
this.CollectionService.getallCollections().subscribe((数据:Collection_info[])=>{
this.Collection_info=数据;
对于(var i=0;i尝试以下方法:

export class Test implements OnInit {
    result_arr = [];

    ngOnInit() {
         this.get_All_Col_data(myfrugalmap, Marker_array)
    }

    get_All_Col_data(map, markers){
        const myIcon_Col = L.icon({
            iconUrl: 'https://img.icons8.com/ultraviolet/40/000000/collect.png'
        });
        const myIcon_vente = L.icon({
        iconUrl: 'https://img.icons8.com/color/50/000000/low-price-euro.png'
        });
        this.CollectionService.getallCollections().subscribe((data: Collection_info[])                                 
         =>{
             this.Collection_info = data;
             for(var i =0; i<this.Collection_info.length;i++){
               console.log("name :" + this.Collection_info[i].emailcol);
               console.log("type :" + this.Collection_info[i].type);
               if(this.Collection_info[i].type==='collection'){
                   var m = L.marker([Number(this.Collection_info[i].lat_col), 
                   Number(this.Collection_info[i].long_col)], {icon: myIcon_Col}).addTo(map);
                   m.bindPopup("Collection pt " + this.Collection_info[i].nom_col);
                   markers.push(m);
                  this.result_arr.push(this.Collection_info[i]);
               }else{
                   var m = L.marker([Number(this.Collection_info[i].lat_col), 
                   Number(this.Collection_info[i].long_col)], {icon: myIcon_vente}).addTo(map);
                   m.bindPopup("Collection vente " + this.Collection_info[i].nom_col);
                   this.result_arr.push(this.Collection_info[i]);
                   markers.push(m);
              }
          }
       console.log(this.result_arr)
       });
}
导出类测试实现OnInit{
结果_arr=[];
恩戈尼尼特(){
获取所有列数据(myfrugalmap、标记数组)
}
获取所有颜色数据(地图、标记){
常量myIcon\u Col=L.icon({
伊克努尔:'https://img.icons8.com/ultraviolet/40/000000/collect.png'
});
常数myIcon\u vente=L.icon({
伊克努尔:'https://img.icons8.com/color/50/000000/low-price-euro.png'
});
this.CollectionService.getallCollections().subscribe((数据:Collection_info[]))
=>{
this.Collection_info=数据;
对于(var i=0;i