Tracked and Computed Property
Learn to use tracked and computed properties in Ember controllers.
We'll cover the following...
Tracked property
Tracked properties are used as a decorator to mark a property as tracked. They’re imported from @glimmer/tracking. When a property is marked as tracked, it rerenders the DOM whenever the value of that tracked property is changed. A counter with the increment or decrement functionality needs to be tracked. This allows us to change it without having to render the DOM. Let’s create a counter layout in the practice template to learn about the tracked property:
-
Line 3: We add a
countproperty in anh3tag. We usethisto refer to the properties from controllers. -
Line 5: We create a button and add an
incrementevent handler. -
Line 6: We create a button and add a
decrementevent handler.
Now, let’s open the practice.js controller and add the required property and event handlers:
- Line 3: We import