-
Book Overview & Buying
-
Table Of Contents
Ember.js Cookbook
By :
Using conditionals is fundamental to using Ember's templating engine. In the following recipes, we'll take a look at conditionals and how they work with templates.
Let's take a look at a simple example that displays text if some property is true.
Create a new project and generate a new controller called conditional. Run this command in the root of the application folder to create controller and template:
$ ember g controller conditional $ ember g template conditional
This will create the conditional controller.
Update the router.js file with the new conditional route:
// app/router.js
…
Router.map(function() {
this.route('conditional');
});This will add a new conditional route. To access this route using the Ember server, open a web browser and navigate to http://localhost:4200/conditional.
Update the conditional controller with the isHomeworkDone property:
// app/controllers/conditional.js import Ember from 'ember'; export default Ember...
Change the font size
Change margin width
Change background colour