Skip to content

Instantly share code, notes, and snippets.

@joostme
Last active July 18, 2018 16:43
Show Gist options
  • Select an option

  • Save joostme/a9ddba47161f8ea968cccb52084ffccc to your computer and use it in GitHub Desktop.

Select an option

Save joostme/a9ddba47161f8ea968cccb52084ffccc to your computer and use it in GitHub Desktop.
@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