Last active
November 11, 2021 15:40
-
-
Save rainerhahnekamp/5cefe4cbe75b7378717d52f67b1eefa8 to your computer and use it in GitHub Desktop.
This file contains 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: '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