Skip to content

Instantly share code, notes, and snippets.

@sukima
Last active January 24, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/b084b42638abe16999dc63d60c0c1e61 to your computer and use it in GitHub Desktop.
Save sukima/b084b42638abe16999dc63d60c0c1e61 to your computer and use it in GitHub Desktop.
You still need settters
import Controller from '@ember/controller';
import { computed } from '@ember/object';
export default Controller.extend({
appName: 'Ember Twiddle',
isEvenLength: computed('appName', function() {
return this.appName.length % 2 === 0;
}),
actions: {
withOutSetter(value) {
this.appName = value;
},
withSetter(value) {
this.set('appName', value);
}
}
});
<h1>Welcome to {{this.appName}}</h1>
<p>There are an {{if this.isEvenLength "even" "odd"}} number of characters.</p>
<fieldset>
<label>Without setter:</label>
<input
value={{this.appName}}
oninput={{action "withOutSetter" value="target.value"}}
>
</fieldset>
<fieldset>
<label>With setter:</label>
<input
value={{this.appName}}
oninput={{action "withSetter" value="target.value"}}
>
</fieldset>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment