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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -