Skip to content

Instantly share code, notes, and snippets.

@lennyburdette
Created June 21, 2018 19:02
Show Gist options
  • Save lennyburdette/bed5e52bb958effd22856503752106b4 to your computer and use it in GitHub Desktop.
Save lennyburdette/bed5e52bb958effd22856503752106b4 to your computer and use it in GitHub Desktop.
notifyPropertyChange property path
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
this.set('foo', {
bar: 'abc'
});
this.set('baz', Ember.Object.create({
quux: 'def'
}));
},
actions: {
fooBarChange(value) {
if (/^[a-z]*$/.test(value)) {
this.set('foo.bar', value);
}
// This doesn't work
this.notifyPropertyChange('foo.bar');
},
barQuuxChange(value) {
if (/^[a-z]*$/.test(value)) {
this.set('baz.quux', value);
}
this.get('baz').notifyPropertyChange('quux');
}
}
});
<h4>Try typing letters and number (only letters are valid)</h4>
<i>Doesn't work</i><br>
<input value={{foo.bar}} oninput={{action "fooBarChange" value="target.value"}}><br>
Result: {{foo.bar}}
<br><br>
<i>Works</i><br>
<input value={{baz.quux}} oninput={{action "barQuuxChange" value="target.value"}}><br>
Result: {{baz.quux}}
{
"version": "0.15.0",
"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.2.0",
"ember-template-compiler": "3.2.0",
"ember-testing": "3.2.0"
},
"addons": {
"ember-data": "3.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment