ember.js - Where should I set defaults on components with attributeBindings? -
i have component {{upload-image src=foo.bar}}
. when foo.bar
falsy want give different value. setting value in init
so:
import ember 'ember'; export default ember.component.extend({ attributebindings: ['src'], tagname: 'img', init: function(){ this.set('src', 'http://www.placecage.com/40/40'); this._super(); this.set('src', 'http://www.placecage.com/40/40'); }, click: function(){ console.log(this.get('src')); } });
however doesn't work. image gets rendered value pass in, not new one. when click image log placecage image. instead if try override later on didinsertelement
works expected:
import ember 'ember'; export default ember.component.extend({ attributebindings: ['src'], tagname: 'img', didinsertelement: function(){ this.set('src', 'http://www.placecage.com/40/40'); }, click: function(){ console.log(this.get('src')); } });
it seems bit silly have render out , able change value causing (i presume) re-render. what's appropriate place check if src
falsy , set default , expected results?
in ember 1.13 can in
attributebindings: ['src:src'], didinitattrs() { this.set('src', <new value>); }
or falsy logic outside of component , pass in.
Comments
Post a Comment