Last active
July 18, 2018 16:43
-
-
Save joostme/a9ddba47161f8ea968cccb52084ffccc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'edit-form', | |
| templateUrl: './edit-form.component.html', | |
| styleUrls: ['./edit-form.component.scss'] | |
| }) | |
| export class EditFormComponent implements OnDestroy { | |
| subscriptions: Subscription[]; | |
| @ViewChild('form') | |
| form; | |
| constructor( | |
| private actions: Actions, | |
| private router: Router, | |
| private activatedRoute: ActivatedRoute | |
| ) { | |
| this.subscriptions = [ | |
| this.actions | |
| .pipe( | |
| ofType(FormActionType.FormSubmitted), | |
| map((action: FormSubmittedAction) => action.payload), | |
| map(actionResource => { | |
| this.form.reset(); | |
| this.router.navigate(['../'], { relativeTo: this.activatedRoute }); | |
| }) | |
| ) | |
| .subscribe(), | |
| this.actions | |
| .pipe( | |
| ofType(FormActionType.FormSubmissionFailed), | |
| map((action: FormSubmissionFailedAction) => action.payload), | |
| map(issues => this.form.setErrors(toFormErrors(issues))) | |
| ) | |
| .subscribe() | |
| ]; | |
| } | |
| ngOnDestroy() { | |
| this.subscriptions.forEach(subscription => subscription.unsubscribe()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment