Passing variables


#1

I have a component that is used to set or unset a variable

showExpense : true, actions: { toggleExpense() { debugger; this.toggleProperty(‘showExpense’); }

but I am trying to acces this variable “showExpense” in another template not belonging to this component in fact it is a template of a route, hence the variable is not accessible. Is there a way to use it there?


#2

If the variable needs to be used higher up the template hierarchy, then you’ll need to move the variable and the action up as well. Then you will want to pass down a “closure action” to your current component for the component to call when your show expense button gets clicked. More details here: https://guides.emberjs.com/v2.7.0/components/triggering-changes-with-actions/

If things are still unclear, we may need to improve the guides to explain that better …


#3

And what about when I’m have to trigger an action in component 2 by clicking in an element of component 1? This components are siblings:

{{component-1}} {{component-2}}

Here is my question: Call action from sibling component I think it is related.


#4

That was pretty clear. My doubt here is, is there any way to pass properties between a component and a router? My application basically has a router with a button, so when a click is registered I’ll have to fetch data in the model through component. So i used component to hold a variable that decides if the data is visible or not. And so i’ll have to pass this variable to route to update the view.