vendredi 17 juin 2022

Ember.js change tracked variable in child component

I am new to ember.js and wanna know what's the best way to alter @tracked variable in child component.

Assume this structure:

Parent
  --- Component1
  • Parent controller

    @tracked
    number = 1
    
  • Parent.hbs

    <Component1 @number= />
     
    
  • Component1.hbs

    <button > Add </button>
    
  • Component1.js

    @tracked
    number = this.args.number
    
    @action
    addNumber(){
        this.number += 1;
        console.log(this.number)
    }
    

The number did addon in the Component1 and print the number every time I clicked the Add button, however, it didn't reflect to Parent level.




Aucun commentaire:

Enregistrer un commentaire