Components are modular chunks of UI, and can have a .js
file, a .hbs
file or both. We'll start with the simplest kind of component -- ones that involve no state of their own (but can be passed state from the outside world), and are defined only by a .hbs
template file. When we start using components that own private state, they will involve .js
files.
Usually we'd use Ember CLI to generate new components, but in this case we'll just create a new .hbs
file for each.
The goal of this step is to break various parts of app/templates/application.hbs
into their own respective .hbs
files as template-only components. In the end, your application.hbs
should look like
- Create
app/templates/components/team-selector.hbs
- Move
<nav class="team-selector">...</nav>
into it - Replace what you deleted from
application.hbs
with<TeamSelector />
- Move
- Create
app/templates/components/team-sidebar.hbs
- Move
<section class="team-sidebar">...</section>
into it - Replace what you deleted from
application.hbs
with<TeamSidebar />
- Move
- Create
app/templates/components/channel-header.hbs
- Move
<header class="channel-header">...</header>
into it - Replace what you deleted from
application.hbs
with<ChannelHeader />
- Move
- Create
app/templates/components/chat-message.hbs
- Move one of the
<div class="message">...</div>
into it- NOTE: the starting point HTML has more than one of these. Pick one to use to create the component, and for now we'll just use the one component several times
- Replace what you deleted from
application.hbs
with 2<ChatMessage />
s
- Move one of the
- Create
app/templates/components/channel-footer.hbs
- Move
<footer class="channel-footer">...</footer>
into it - Replace what you deleted from
application.hbs
with<ChannelFooter />
- Move
At the end of this, you should see no change to the rendered HTML at http://localhost:4200.
Congrats! You've just broken down all of that HTML into components!