Component Events from NGXS
@Output() search = new EventEmitter<string>();@Component({
selector: 'app-email-list',
template: `
<app-message *ngFor="let message of messages$ | async" [message]="message"></app-message>
<app-button (click)="refresh()">Refresh messages</app-button>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class EmailListComponent {
@Select(MessagesState.getMessages) messages$: Observable<Message[]>;
@Output() messagesLoaded = new EventEmitter<Message[]>();
constructor(private store: Store) {}
refresh(): void {
this.store.dispatch(new LoadMessages()).subscribe(() => {
const messages = this.store.selectSnapshot(MessagesState.getMessages);
this.messagesLoaded.emit(messages);
});
}
}Last updated

