Model Resolution
Here, you’ll learn about a rookie trap in Ember.js by making little changes in our application.
Since we are talking about router subtleties in this chapter, let’s see a rookie trap.
Make the following tiny change in the band-list component template:
Press + to interact
{{!-- app/components/band-list.hbs --}}<ul class="pl-2 pr-8">{{#each this.bands as |item|}}<li class="mb-2"><LinkToclass={{if item.isActive "border-purple-400 border-l-4 pl-2"}}@route="bands.band"{{!-- @model={{item.band.id}} --}}@model={{item.band}}>{{item.band.name}}</LinkTo></li>{{/each}}</ul>
Instead of passing the id
of each band to the LinkTo
, we pass the band object itself.
Everything keeps working as before, yet there’s something strange going on. If you put a breakpoint in the bands.band
route’s model hook, you’ll find that when you click the LinkTo
we just changed or any of the ...
Access this course and 1400+ top-rated courses and projects.