Skip to content

Instantly share code, notes, and snippets.

@rainerhahnekamp
Last active November 11, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rainerhahnekamp/5cefe4cbe75b7378717d52f67b1eefa8 to your computer and use it in GitHub Desktop.
Save rainerhahnekamp/5cefe4cbe75b7378717d52f67b1eefa8 to your computer and use it in GitHub Desktop.
@Component({
selector: 'eternal-edit-customer',
template: ` <eternal-customer
*ngIf="customer$ | async as customer"
[customer]="customer"
(save)="this.submit($event)"
(remove)="this.remove($event)"
></eternal-customer>`,
})
export class EditCustomerComponent implements OnInit {
customer$: Observable<Customer> | undefined;
constructor(private store: Store, private route: ActivatedRoute) {}
ngOnInit() {
this.customer$ = this.store
.select(
fromCustomer.selectById(Number(this.route.snapshot.params.id || ''))
)
.pipe(
map((customer) => {
return { ...customer };
})
);
}
submit(customer: Customer) {
this.store.dispatch(
CustomerActions.update({ customer })
);
}
remove(customer: Customer) {
this.store.dispatch(
CustomerActions.remove({ customer })
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment