Skip to content

Commit

Permalink
refactor: hero-search の view が受け取る input を signal inputs に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kasaharu committed Feb 25, 2024
1 parent 3a880e2 commit 782631a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { AsyncPipe } from '@angular/common';
import { Component, computed, inject } from '@angular/core';
import { LyHeroSearchComponent } from '../../views/ly-hero-search/ly-hero-search.component';
import { HeroSearchService } from './hero-search.service';

@Component({
selector: 'app-hero-search',
standalone: true,
imports: [AsyncPipe, LyHeroSearchComponent],
imports: [LyHeroSearchComponent],
templateUrl: './hero-search.component.html',
styleUrls: ['./hero-search.component.scss'],
providers: [HeroSearchService],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
<input #searchBox id="search-box" (input)="search(searchBox.value)" />

<ul class="search-result">
@if (heroes) {
@for (hero of heroes; track hero) {
<li>
<a routerLink="/detail/{{ hero.id }}">
{{ hero.name }}
</a>
</li>
}
@for (hero of heroes(); track hero.id) {
<li>
<a routerLink="/detail/{{ hero.id }}">{{ hero.name }}</a>
</li>
}
</ul>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Output, input } from '@angular/core';
import { RouterLink } from '@angular/router';
import { Hero } from '../../../../domain/hero';

Expand All @@ -10,7 +10,7 @@ import { Hero } from '../../../../domain/hero';
styleUrls: ['./ly-hero-search.component.scss'],
})
export class LyHeroSearchComponent {
@Input() heroes: Hero[] = [];
heroes = input.required<Hero[]>();
@Output() heroSearched = new EventEmitter<string>();

search(name: string): void {
Expand Down

0 comments on commit 782631a

Please sign in to comment.