Skip to content

Commit

Permalink
linkedSignal shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesHoppe committed Nov 3, 2024
1 parent b6cef1d commit 59ffdb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app/books/book/book.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<div class="card-title">
<h2>
{{ title() }}
<span class="badge bg-secondary me-2">{{ b.rating }}</span>
<span class="badge bg-secondary me-2">{{ rating() }}</span>
</h2>
</div>
<p>{{ b.description }}</p>

<button [disabled]="b.rating <= 1" class="btn btn-primary me-2" (click)="doRateDown()">-1</button>
<button [disabled]="b.rating >= 5" class="btn btn-primary" (click)="doRateUp()">+1</button>
<button [disabled]="rating() <= 1" class="btn btn-primary me-2" (click)="doRateDown()">-1</button>
<button [disabled]="rating() >= 5" class="btn btn-primary" (click)="doRateUp()">+1</button>
</div>
</div>
4 changes: 4 additions & 0 deletions src/app/books/book/book.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class BookComponent {
computation: book => book.rating,
});

// this also works:
// rating = linkedSignal(() => this.book().rating);


doRateUp() {
const newRating = this.rating() + 1;
this.rating.set(newRating);
Expand Down

0 comments on commit 59ffdb2

Please sign in to comment.