Computed Properties
Last updated
Was this helpful?
Was this helpful?
import Component from '@ember/component';
import { computed } from '@ember/object/computed';
const UserProfile = Component.extend({
name: 'Chris',
age: 32,
bio: computed('name', 'age', function() {
return `${this.get('name')} is `${this.get('age')}` years old!`;
}),
})
export default UserProfile;import Component from '@ember/component';
import { computed } from '@ember/object/computed';
const UserProfile = Component.extend({
name: 'Chris',
age: 32,
bio: computed('name', 'age', function(this: UserProfile) {
// ^---------------^
// `this` tells TS to use `UserProfile` for `get` and `set` lookups;
// otherwise `this.get` below would not know the types of `'name'` or
// `'age'` or even be able to suggest them for autocompletion.
return `${this.get('name')} is `${this.get('age')}` years old!`;
}),
})
export default UserProfile;