2016-08-22 24 views

回答

11

動畫即將推出ng2-bootstrap。你只需要等一下。

1)今天,你可以作爲替代方法利用了以下內容:

@Component({ 
    selector: 'my-app', 
    template: ` 
     <button type="button" class="btn btn-primary" 
      (click)="isCollapsed = !isCollapsed">Toggle collapse 
     </button> 
     <div (collapsed)="setHeight(el, 0)" 
      (expanded)="setHeight(el, 0);setHeight(el, el.scrollHeight)" 
      [collapse]="isCollapsed" 
      class="card card-block card-header block" #el> 
     <div class="well well-lg">Some content</div> 
     </div> 
    `, 
    styles: [` 
    .block { 
     display: block !important; 
     overflow: hidden !important; 
     -webkit-transition: height .5s; 
     transition: height .5s; 
    } 
    `] 
}) 
export class App { 
    isCollapsed: boolean = true; 

    constructor(private renderer: Renderer) { } 

    setHeight(el, height) { 
    this.renderer.setElementStyle(el, 'height', height + 'px'); 
    } 
} 

參見工作Plunker Example

2)沒有CollapseDirective指令即可像這樣做

@Component({ 
    selector: 'my-app', 
    template: ` 
    <button type="button" class="btn btn-primary" 
     (click)="height = height ? 0 : el.scrollHeight">Toggle collapse 
    </button> 

    <div  
     class="card card-block card-header block" [style.height]="height + 'px'" #el> 
     <div class="well well-lg">Some content</div> 
    </div> 
    `, 
    styles: [` 
    .block { 
     overflow: hidden; 
     -webkit-transition: height .5s; 
     transition: height .5s; 
    } 
    `] 
}) 
export class App { 
    height = 0; 
} 

Plunker Example

+0

雖然我們正在等待升級,這對我的作品! – caballerog

+0

仍然迫切需要更新... – Scipion

+1

截至今日,有沒有人知道動畫是否登陸ng2-bootstrap?事實上,甚至更好,因爲他們登陸哪個版本,如果有的話?無法從他們的問題中找出https://github.com/valor-software/ng2-bootstrap/issues/355。感謝任何人可以擺脫光線 – superjos