【发布时间】:2015-12-24 06:14:48
【问题描述】:
在这个问题上已经工作了几个小时,但似乎无法找到解决方法(尽管我阅读了数十页)。 我在页面上有一个引导选项卡系统。在第三个选项卡上,我有一个谷歌地图 div。我知道,由于选项卡一开始不可见,因此地图 div 不会正确呈现地图,因此在选择选项卡时必须以某种方式刷新它。 起初我尝试刷新地图但无法使其正常工作,然后我决定尝试使用 NG-IF 条件再次对 div 进行角度渲染,但再次出现问题......
在 HTML 文件中的标签是这样的:
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a show-tab href="#informations" data-toggle="tab">Informations client</a></li>
<li ng-if="!client.isNew"><a show-tab href="#contacts" data-toggle="tab">Contacts</a></li>
<li ng-if="!client.isNew"><a show-tab href="#geolocalisation" data-toggle="tab">Géolocalisation</a></li>
<li ng-if="!client.isNew"><a show-tab href="#locations" data-toggle="tab">Locations</a></li>
</ul>
<div id="my-tab-content" class="tab-content tab-container">
<div class="tab-pane fade in active" id="informations"></div>
<div class="tab-pane fade in active" id="some_other_stuff"></div>
<div class="tab-pane fade" id="geolocalisation">
<ui-gmap-google-map center='map.center' zoom='map.zoom' refresh='map.refresh' ng-if="gmap_visible"></ui-gmap-google-map>
</div>
<div class="tab-pane fade in active" id="a final tab"></div>
</div>
在我的页面控制器中,我将 gmap_variable 初始化为 false,因此未呈现 ui-gmap-google-map div:
myApp.controller('ClientsController', ['$scope', '$http', '$location', '$routeParams', 'modalService', 'uiGmapGoogleMapApi', function($scope, $http, $location, $routeParams, modalService, uiGmapGoogleMapApi){
$scope.gmap_visible = false;
}
最后,我使用选项卡的指令来阻止单击选项卡时的导航,并认为我可以更新其中的 gmap_visible 变量:
myApp.directive('showTab',
function () {
return {
link: function (scope, element, attrs) {
element.click(function(e) {
e.preventDefault();
$(element).tab('show');
if (attrs.href == '#geolocalisation'){
scope.$parent.gmap_visible = true;
}
});
}
};
});
不幸的是,这似乎不起作用,我的谷歌地图 div 没有呈现...(我尝试在指令中使用 scope=false,但它也不起作用)
那里有解决方法,或者更好的是可以直接在 ng-if 中使用某些东西,例如
<ui-gmap-google-map center='map.center' zoom='map.zoom' refresh='map.refresh' ng-if="parentElement.hasClass('active')">
这会使任何进一步的代码变得无用?
提前谢谢!
【问题讨论】:
标签: angularjs google-maps tabs angular-ui-bootstrap