2017-10-17 7 views
0

ユーザーがボタンをクリックすると、このイベントをキャッチして停止する指示があります。次にモーダルが開き、ユーザーの確認を求められます。ユーザーが確認したら、以前のイベントを再開する必要があります。角度の再開イベントの伝播

停止したイベントを再開するにはどうすればよいですか?

例:私にとって

markAsSeen($event) : void { 

    // pause whatever user wanted to click 
    $event.stopPropagation(); 

    // open modal and ask user for confirmation 
    let modalInstance = this.modalService.openConfirmationModal(); 

    // on modal close, if positive event continue whatever user clicked 
    modalInstance.onClose((response) => { 
     if(response) { 
      // this line should resume $event 
      $event.originalEvent(); // how to achieve this? 
     } 
    }) 
} 
+0

あなたはもう少しあなたの必要性を描写できますか? – Stefdelec

+0

チェックを編集してください。私はこの質問のようなものが必要ですが、角度は4です。https://stackoverflow.com/questions/7811959/how-to-continue-event-propagation-after-cancelling – Mardari

+1

イベントを再開することができますSubject Behaviorsを使用してモーダルからコンポーネントにメッセージを渡すことができます(https://stackoverflow.com/questions/36639486/angular2-manually-firing-click-event-on-particular-element/36639596#36639596 –

答えて

1

これは、2つの異なるイベントで、最初のものはopenModalにここですが(なぜあなただ​​けのモーダルを開けないのですか?)無用に見え、もう一つは確認しますユーザーが確認をクリックしたとき。

これは最も簡単な方法です。最初のイベントエミッタが必要な場合はモーダルを開き、2番目の場合は正の場合は確認プロセスを開始します。もう1つの方法は、あなたの確認に「ステータス」変数を​​追加することです-1開始しない(=モーダルクローズ)、1は肯定的な確認、0は進行中です。

最後にevent.targetがクリックされたターゲットが編集

ある

onClick(event) { 
if (!this.element.nativeElement.contains(event.target)) { 
     closeModal(); // or not 
    } 
} 

のようなものを使用、離れた場所でクリックしてユーザーを避けるために:のonClickは

@Component({selector..., host: { 
    '(document:click)': 'onClick($event)', 
    }}); 
を@Componentに追加する必要があります