whyAto8 whyAto8 - 1 year ago 78
Javascript Question

Ember - child component updating a property coming from query params via parent component

I am using Ember 1.13.0 and trying to update a property coming from query params in a child component.

In child component js, when "time" is not defined, I am setting it to 1200. If i log the value of "time" (this.get('time')) in child component, after i update it, i can see its value being updated. But its doesn't get through to parent component action.

So, why I am not able to get its value in parent, if its getting updated in child?

Top level component:

{{parent-component time = model.params.incomingTime}}

Parent component:

{{child-component time=time}}

Parent component JS:

actions: {
var t = this.get('time')

Child component:

<div>Time is {{currentTime}}</div>

Child component JS:

currentTime: function(){
return time;
} else {
return '1200'

Top level route:

var route = Ember.Route.extend({
queryParams: {
time: {refreshModel:true, replace: false}
model: function(params){
return Ember.RSVP.hash({ params: params})
setupController: function(controller, model) {
controller.set('model', model);

Answer Source

I got it working by declaring new CP in parent component and returning simply "time" from that. Now I am passing that CP to child and then updating it via action in parent. This way it seems to work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download