html - Angular Google Map on multiple Tabs with same Controller and same Template -
html - Angular Google Map on multiple Tabs with same Controller and same Template -
i'm working ionic , angularjs , have google map included. have template , controller map , utilize map on 2 tabs.
.state('tab.map1', { url: '/tab1/map', views: { 'map1-tab': { templateurl: 'templates/map.html', controller: 'mapcontroller' } } }) .state('tab.map2', { url: '/tab2/map', views: { 'map2-tab': { templateurl: 'templates/map.html', controller: 'mapcontroller' } } })
html:
<div id="map"></div>
controller:
$scope.map = new google.maps.map(document.getelementbyid('map'), mapoptions);
url on first tab: /tab1/map
url on sec tab: /tab2/map
now when phone call 1 of url's fine , can see map. when alter tab can't see map anymore. div seems empty. after page reload, map visible. knwo how deal "same" page on multiple tabs? in advance.
if else has same issue, here solution:
the problem was, used same html both tabs, div's shouldn't have same id.
.state('tab.map1', { url: '/tab1/map', views: { 'map1-tab': { templateurl: 'templates/map1.html', controller: 'mapcontroller' } } }) .state('tab.map2', { url: '/tab2/map', views: { 'map2-tab': { templateurl: 'templates/map2.html', controller: 'mapcontroller' } } })
html first tab:
<div id="map1"></div>
html sec tab:
<div id="map2"></div>
and in controller logic
if ($location.path() == 'tab1\map'){ $scope.map = new google.maps.map(document.getelementbyid('map1'), mapoptions); }else{ $scope.map = new google.maps.map(document.getelementbyid('map2'), mapoptions); }
that working me, map visible when changing between tabs.
html angularjs google-maps tabs ionic-framework
Comments
Post a Comment