0
同時にディレクティブは実行して行動することを許可する:角度2、私は送信ボタンをダブルクリックを防止ディレクティブを持って
私は、共有モジュールで使用しているうちimport { Directive, Component, OnInit, AfterViewInit, OnChanges, SimpleChanges, HostListener, ElementRef, Input, HostBinding } from '@angular/core';
@Directive({
selector: 'button[type=submit]'
})
export class PreventDoubleSubmit {
@HostBinding() disabled:boolean = false;
@Input() valid:boolean = true;
@HostListener('click')
onClick() {
console.log("aaa");
this.disabled = true;
}
}
:
import { NgModule } from '@angular/core';
import { PreventDoubleSubmit } from '../shared/prevent-double-submit.directive';
@NgModule({
declarations: [
PreventDoubleSubmit
],
exports: [
PreventDoubleSubmit
]
})
export class SharedModule{}
これをapp.moduleで使用します。アプリ内のどのフォームでも、最初にクリックしたときにボタンが正しく無効になります。しかし、フォーム内の元のアクションは現在全く実行されません。それは、指示がすべてを優先し、何か他のことが起きないようにしているかのようです。
<form (ngSubmit)="onSubmit(f)" #f="ngForm" class="generalForm"></form>
そしてtypescriptですで、私はちょうど使用します:
私は、次のformタグ使ってい
onSubmit(form: NgForm) {
console.log("This is the code I want to perform");
}
クリックの代わりに提出する聴覚 – JEY
@JEY Hmmはそれを試みましたが動作しませんでした。同じ結果。 –
コンポーネントが定義されている場所でモジュール宣言を提供できますか? – JEY