2016-09-20 34 views
0

Ng2-modalを使用しています。ページが読み込まれるとすぐにmyModal.open()関数を起動する方法を理解できません。ボタンにアタッチすると、すべてが正常に動作します。(click)="myModal.open"多くの研究の後、私はspys、hooks、および複雑なJquery関数を参照する答えを見てきました。 javascriptと同様の関数を呼び出す簡単な方法はありませんonload="myModal.open()"モーダル関数の呼び出しを呼び出す

答えて

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(); 
    } 
関連する問題