2016-09-20 52 views
0

我正在使用Ng2模式,並且無法弄清楚如何在頁面加載後立即激活myModal.open()函數。如果你把它連接到一個按鈕(click)="myModal.open"一切工作正常。經過大量研究,我看到了引用spys,鉤子和複雜Jquery函數的答案。有沒有簡單的方法來調用類似javascripts onload="myModal.open()"的功能?激發模式函數onload

回答

0

@Viewchild和ngOnInit()爲我解決了這個問題,下面是一個例子。

部件

@Component({ 
    template: ' <modal #mymodal> 
     <modal-header> 
      <h1>test</h1> 
     </modal-header> 

     <modal-content> 
      test test test 
     </modal-content> 
     <modal-footer> 
     </modal-footer> 
    </modal>',  
    }) 
    export class GasTroubleComponent implements OnInit { 
     @ViewChild('mymodal') mymodal: Modal; 

     ngOnInit(){ 
     this.modalSoundVerification.open(); 
    }