Skip to content

Instantly share code, notes, and snippets.

@baroquon
Forked from gitjeff05/application.controller.js
Created October 28, 2015 18:26
Show Gist options
  • Save baroquon/96549a404a1ff9d802f7 to your computer and use it in GitHub Desktop.
Save baroquon/96549a404a1ff9d802f7 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Notifying a property change on a property passed into a child component',
description: 'There is a parent component with some buttons. When a user clicks on a button, the buttons\'s action changes the property. Since the changed property is passed into the wrapped component, you would expect that it\'s observer would fire also. But it does not. To try this, just type in 1233 and you will see that the last 3 will not render.'
});
<h1>{{appName}}</h1>
<p>{{description}}</p>
{{pin-entry}}
import Ember from 'ember';
export default Ember.Component.extend({
pinValue: null,
counter: 0,
numbers: [1, 2, 3, 4, 5],
actions: {
addNumber: function (number) {
let counter = this.get('counter');
this.set('pinValue', number);
this.set('counter', counter + 1);
}
}
});
{{pin-input pinValue=pinValue counter = counter}}
{{#each numbers as |num|}}
<button {{action "addNumber" num}}>{{num}}</button>
{{/each}}
import Ember from 'ember';
export default Ember.Component.extend({
value: null,
pinValue: null,
onDidChangeInput: function() {
var current = this.$('input').val();
this.set('value', current + this.get('pinValue'));
}.observes('counter')
});
<input type=text value={{value}}>
{
"version": "0.4.14",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment