Emberjs How to update property on a component from route?

DeividKamui

Hi I would like to know what's the proper way to update a property on a component from the route?.

A little background on what I want to do:

I have two custom Buttons that I called CardButtons (based on material desing) next to one blank area called description, what I want is to create a hover event that triggers an ajax call to retrive detailed data from a data base and render it on the description area.

CHECK UPDATE

So far I have created a route like this:

export default Ember.Route.extend({

selectedModule: '',

model: function () {

    return {
        selectedModule: 'employeeModule'
    };
},


actions: {

    showDescription: function (params) {

        this.set('model.selectedModule', params);

    }

}});

My route template call my component like this:

<div class="row">  
   {{sis-db-description-render idTitle=model.selectedModule}}
</div>

and the component is defined like this:

export default Ember.Component.extend({

info: null,
ready: false,

didInsertElement: function () {

    this.queryData();


},

queryData: function (){
     /** Does an Ember.$.post request to the API  with the idTitle as param**/
}
});

the first time this executes it load perfectly the detail data but when I try to refresh the data the event does not trigger a second call. I bealive it is beacause I'm not updating the model in a proper way.

Any idea on how to update the component property?

UPDATE:

Thanks to @kumkanillam I was able to find a way on my route I added the next code:

 setupController: function (controller, model) {

    this._super(...arguments); //if its new/index.js route file then you can use controller argument this method.
    controller.set('selectedModule', 'employeeModule');
},


actions: {

    showDescription: function (params) {

        console.info(params);
        this.controllerFor('new.index').set('selectedModule', params);

    }

}

By doing so now the view updates the content every time, I still don't know if this is the correct way to do it but it works for now.

Ember Freak

In the below code, model is not defined in route. it's defined in corresponding controller through setupController hook.

showDescription: function (params) {
  this.set('model.selectedModule', params);
}

So in your case either you can define action in controller and update model.selectedModule
If you want to do it in route,

showDescription: function (params) {
      let cont = this.controllerFor('route-name');
      cont.set('model.selectedModule', params);
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Emberjs - how do I set a property on an itemController from a route?

From Dev

EmberJS, polling, update route's model, re-render component

From Dev

emberjs component property not updated?

From Dev

EmberJS: How to call a component function from a controller and calculate the component data

From Dev

EmberJS: How to call a component function from a controller and calculate the component data

From Dev

How to update props of initial route in a NavigatoriOS component?

From Dev

Component to be notified on route change in EmberJS 2

From Dev

Maintaining component state through route transitions - EmberJS

From Dev

How to call method of child component from parent in EmberJS

From Dev

How to refresh model data from inside component in EmberJS?

From Dev

How to refresh model data from inside component in EmberJS?

From Dev

How to call method of child component from parent in EmberJS

From Dev

How dynamically load route in EmberJS?

From Dev

Emberjs-1.0 component and compute property in controller

From Dev

modify a property of a component through a controller in emberJS

From Java

Update parent component property from child component in Angular 2

From Dev

Getting ExpressionChangedAfterItHasBeenCheckedError error I update property of a Component from another Component

From Dev

EmberJS loading view from controller not route

From Dev

setting data from route to controller error in Emberjs

From Dev

Route that observes property on component that links to it

From Java

EmberJS: How to load multiple models on the same route?

From Dev

EmberJS - How to scroll to outlet after a Route?

From Dev

EmberJS - How to scroll to outlet after a Route?

From Dev

How to use custom "abstract" route in emberjs

From Dev

How to access the "key" property from a reactjs component

From Dev

How to get property from component when testing?

From Dev

How to change controller property from component?

From Dev

EmberJS trigger action on parent component from child

From Dev

Accessing "this" as the parent from callbacks emberjs nested component

Related Related

  1. 1

    Emberjs - how do I set a property on an itemController from a route?

  2. 2

    EmberJS, polling, update route's model, re-render component

  3. 3

    emberjs component property not updated?

  4. 4

    EmberJS: How to call a component function from a controller and calculate the component data

  5. 5

    EmberJS: How to call a component function from a controller and calculate the component data

  6. 6

    How to update props of initial route in a NavigatoriOS component?

  7. 7

    Component to be notified on route change in EmberJS 2

  8. 8

    Maintaining component state through route transitions - EmberJS

  9. 9

    How to call method of child component from parent in EmberJS

  10. 10

    How to refresh model data from inside component in EmberJS?

  11. 11

    How to refresh model data from inside component in EmberJS?

  12. 12

    How to call method of child component from parent in EmberJS

  13. 13

    How dynamically load route in EmberJS?

  14. 14

    Emberjs-1.0 component and compute property in controller

  15. 15

    modify a property of a component through a controller in emberJS

  16. 16

    Update parent component property from child component in Angular 2

  17. 17

    Getting ExpressionChangedAfterItHasBeenCheckedError error I update property of a Component from another Component

  18. 18

    EmberJS loading view from controller not route

  19. 19

    setting data from route to controller error in Emberjs

  20. 20

    Route that observes property on component that links to it

  21. 21

    EmberJS: How to load multiple models on the same route?

  22. 22

    EmberJS - How to scroll to outlet after a Route?

  23. 23

    EmberJS - How to scroll to outlet after a Route?

  24. 24

    How to use custom "abstract" route in emberjs

  25. 25

    How to access the "key" property from a reactjs component

  26. 26

    How to get property from component when testing?

  27. 27

    How to change controller property from component?

  28. 28

    EmberJS trigger action on parent component from child

  29. 29

    Accessing "this" as the parent from callbacks emberjs nested component

HotTag

Archive