Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Created October 19, 2018 21:59
Show Gist options
  • Save LayZeeDK/496a4251ae326320ad9e3f6886416259 to your computer and use it in GitHub Desktop.
Save LayZeeDK/496a4251ae326320ad9e3f6886416259 to your computer and use it in GitHub Desktop.
Search component that delegates to search BLoC
<div cdkTrapFocus [cdkTrapFocusAutoCapture]="false">
<mat-form-field appearance="outline" style="width: 80%;">
<input
matInput
placeholder="Search for..."
ngModel (ngModelChange)="search($event)">
</mat-form-field>
</div>
<span> {{ preamble$ | async }} </span>
<ul>
<li *ngFor="let result of results$ | async">
{{ result }}
</li>
</ul>
import { Component } from '@angular/core';
import { SearchBloc } from '../../business-logic/search';
@Component({
selector: 'app-search',
styleUrls: ['./search.component.css'],
templateUrl: './search.component.html',
})
export class SearchComponent {
readonly preamble$ = this.bloc.preamble$;
readonly results$ = this.bloc.results$;
constructor(private readonly bloc: SearchBloc) {}
search(query: string): void {
this.bloc.query.next(query);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment