I have an effect that an action sent a file over and need to send an action back so that I can update state via a reducer.
@Effect()
uploadChange$: Observable<Action> = this.actions$.pipe(
ofType(OurActionTypes.UploadChange),
// map(action => action['payload'])
map(action => {
// console.log(action['payload']);
var input = action['payload'];
const reader = new FileReader();
reader.onload = e => {
const raw = (<FileReader>e.target).result as string;
const res = JSON.parse(raw);
console.log(res);
// this.uploadedSpec = res;
// return of(new UploadComplete(res));
}
reader.readAsText(input);
}),
map((res) => new OurActions.UploadComplete(res))
);
I cannot quite figure out a way to send the results of the upload to the action OurActions.UploadComplete. The way above has res as underfined. Needing help with this one thing.
from Send an action with file contents in NgRx / Angular 7
No comments:
Post a Comment