Skip to content

Instantly share code, notes, and snippets.

@ahmetemrekilinc
Last active November 1, 2018 06:30
Show Gist options
  • Save ahmetemrekilinc/072962a3c85e1c5afcd0b2ec1eb8f508 to your computer and use it in GitHub Desktop.
Save ahmetemrekilinc/072962a3c85e1c5afcd0b2ec1eb8f508 to your computer and use it in GitHub Desktop.
ember-two-way-binding-example
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
increaseVar(){
this.set('variable', this.get('variable') + 1);
}
}
});
import Ember from 'ember';
import {computed} from '@ember/object';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
x: 5,
y: 5,
computed2X: computed('x', function(){
return 2 * this.get('x');
}),
computed2Y: computed('y', function(){
return 2 * this.get('y');
}),
actions: {
increaseX(){
this.set('x', this.get('x') + 1);
},
increaseY(){
this.set('y', this.get('y') + 1);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
two way controller x: {{x}}
<button {{action 'increaseX'}} >increase x</button>
{{my-component variable=x }}
{{my-component variable=x }}
computed2X: {{computed2X}}
<br>
one way controller y: {{y}}
<button {{action 'increaseY'}} >increase y</button>
{{my-component variable=(readonly y) }}
{{my-component variable=(readonly y) }}
computed2Y: {{computed2Y}}
<br>
{{outlet}}
<br>
<br>
{{yield}}
component variable: {{variable}}
<button {{action 'increaseVar'}} >increase var</button>
{
"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