は私がangular4でポップアップモーダルため、このチュートリアルの後:私はモーダルの外側をクリックした場合ユーザーがポップアップを外側にクリックするとAngular4のポップアップが閉じられますか?
http://jasonwatmore.com/post/2017/01/24/angular-2-custom-modal-window-dialog-box
を、モーダルが消えます。しかし、ユーザーが閉じるアイコンをクリックするまで、モーダルが消えることは望ましくありません。ここで
はモーダルのOnInit
である:ここで
ngOnInit(): void {
let modal = this;
// ensure id attribute exists
if (!this.id) {
console.error('modal must have an id');
return;
}
// move element to bottom of page (just before </body>) so it can be displayed above everything else
this.element.appendTo('body');
// close modal on background click
this.element.on('click', function (e: any) {
var target = $(e.target);
if (!target.closest('.modal-body').length) {
modal.close();
}
});
// add self (this modal instance) to the modal service so it's accessible from controllers
this.modalService.add(this);
}
は、私が実際に持っているもののplunkerです: https://plnkr.co/edit/gPCTvV?p=preview
:私は角に新しいです/ – Supamiu
Supamiuをなぜかjquyを角度の内側で使用するのは良い習慣ではないと私に教えてください。 – Rahiman
JQueryは角度が何をしているのか、より良い方法で行うのかを判断するためです。 – Supamiu