ionic2 - Array of viewChilds in Angular -
i've sample code that's works nice...
import { component, viewchild, elementref } '@angular/core'; import { navcontroller } 'ionic-angular'; declare var google; @component({ selector: 'home-page', templateurl: 'home.html' }) export class homepage { @viewchild('map') mapelement: elementref; map: any; constructor(public navctrl: navcontroller) { } ionviewdidload(){ this.loadmap(); } loadmap(){ let latlng = new google.maps.latlng(-34.9290, 138.6010); let mapoptions = { center: latlng, zoom: 15, maptypeid: google.maps.maptypeid.roadmap } this.map = new google.maps.map(this.mapelement.nativeelement, mapoptions); } } this display map when it's locates div bellow:
<div #map id="map" style="width: 300px; height: 300px;"></div> but i've array of maps in fact....so, question : how archive array of view-childs ?
i need like...
for(let i=0; < 5; i++) { @viewchild('map' + i) mapelement[i]: elementref; } and function "loadmaps()"
this is more angular question rather ionic2 in fact.
you can use viewchildren y querylist:
first import them:
import { viewchildren,querylist } '@angular/core'; use class viewchild:
@viewchildren("div") divs: querylist<any>
Comments
Post a Comment