Search page 2.component.ts
@Component({
selector: 'app-search-page',
templateUrl: './search-page.component.html',
standalone: true,
imports: [
FormsModule,
CountryTableComponent,
WikiTableComponent,
JournalTableComponent,
NgIf,
NgFor,
AsyncPipe,
],
})
export class SearchPageComponent implements OnInit {
selectedOption = 'countries';
searchTerm = '';
countryResults$?: Observable<Country[]>;
journals$?: Observable<Journal[]>;
constructor(
private countryApiService: CountryApiService,
private journalApiService: JournalApiService
) {}
ngOnInit() {}
onSearch(): void {
console.log(`Searching ${this.searchTerm}`);
switch (this.selectedOption) {
case 'countries':
this.countryResults$ = this.countryApiService
.findByName(this.searchTerm)
.pipe(
tap((results) => {
console.log(`fetched: ${JSON.stringify(results)}`);
})
);
break;
case 'journals':
this.journals$ = this.journalApiService
.findByName(this.searchTerm)
.pipe(
map((journalApiResponse: JournalApiResponse) => {
return journalApiResponse.message.items;
})
);
break;
}
}
}