mardi 18 mai 2021

Emberjs: Use args as tracked property

I am doing a store query in the controller and then passing the result down to a child component.

// Controller
@tracked comment;

@action
async fetchComment() {
  const comment = await this.store.query('note', {
    filter: {
      listing: this.listing.id,
    },
  });

  if (comment && comment.length > 0) {
    this.comment = comment.firstObject;
  }
}


// Template
<MyComponent @comment= />

I want to use the arg to populate a tracked property in the child component.

// Component
@tracked comment = this.args.comment;

I found this does not work but works well as a getter. However with a getter I am unable to set this to null when deleting that record.

I have also tried to set the tracked property in the Constructor but that didnt work either.

I suspect this has something to do with passing in a promise or store object in the args because this works fine with static data.




Aucun commentaire:

Enregistrer un commentaire