Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. @Directive({
  2. selector: '[ifValid]'
  3. })
  4. export class SubmitValidationDirective {
  5.  
  6. @Output('ifValid') valid = new EventEmitter<void>();
  7.  
  8. constructor(
  9. private formRef: NgForm
  10. ) {}
  11.  
  12. private emitIfValid() {
  13. if (this.formRef.valid) {
  14. this.valid.emit();
  15. }
  16. }
  17.  
  18. }
  19.  
  20. <button (ifValid)="save()">
  21.  
  22. private save() {
  23. this.service.push(this.user, this.toCreate)
  24. .pipe(
  25. take(1)
  26. )
  27. .subscribe();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement