2016-03-18 19 views
1

这里就刷新GoogleMap的是我的问题:一个隐藏的DIV中的地图没有显示对角2这是一个隐藏的组件

可能的解决方案:

<div [hidden]="!showMap"> 
    <sebm-google-map #myMap></sebm-google-map> 
</div> 
<button (click)="showMap = true; myMap.triggerResize()">resize</button> 

这可以用一个简单的1个可变的工作,在我来说,我有动态创建论文DIV的,所以我不能指向#myMap那么容易

+0

这是有关调用'myMap.triggerResize()'上的一个特定'使用'* ngFor'创建了一组元素中的'? –

+0

我不知道角2,但可能有相当于ng类。创建一个具有'visibility:hidden; position:absolute; z-index:-100;'的新类,并使用ng-class添加或删除它。我的想法是,如果你使用visiblity:隐藏。它可能工作,因为它仍然可以呈现div。如果这不起作用,你也可以尝试'不透明:0'。其他的东西是让它出现在所有其他东西后面,所以它看起来不在那里。 – user3413723

+0

由* ngFor –

回答

3

这是对所有<sebm-google-map>元素调用triggerResize()

<div *ngFor="let item of items"> <!-- just some ngFor for demo --> 
    <button #myMap (click)="showMap = true; doTriggerResize()">resize</button> 
</div> 
@ViewChildren('myMap') viewChildren:QueryList; 

doTriggerResize() { 
    this.viewChildren.toArray().forEach((e) { 
    e.triggerResize(); 
    }); 
}