Consider the canonical computed property example:
Ember.Object.extend({
firstName: 'Serena',
lastName: 'Fritsch',
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
})
});
ember-computed-template-string
provides a macro which removes the duplication:
import templateString from 'ember-computed-template-string';
Ember.Object.extend({
firstName: 'Serena',
lastName: 'Fritsch',
fullName: templateString("${firstName} ${lastName}")
});
This is an Ember CLI addon, to install:
ember install ember-computed-template-string
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.