@Component({
selector: 'new-story-form',
template: `
<form [formGroup]="newStory"
(submit)="submit($event)"
(success)="onSuccess()"
(error)="onError($event)"
connectForm="newStory">
...controls
<button [disabled]="newStory.invalid" type="submit">Submit</button>
</form>
<div class="alert alert-success" *ngIf="success">Success!</div>
<div class="alert alert-danger" *ngIf="error">{{error}}</div>
`
})
class NewStoryFormComponent {
constructor(private store: Store<AppState> ) {}
onError(error) {
this.error = error;
}
onSuccess() {
this.success = true;
}
submit() {
// You can also take the payload from the form state in your effect
// with the withLatestFrom observable
this.store.dispatch({
type: ADD_STORY,
payload: ...
})
}
}