Agustin Herrera
Agustin Herrera

Reputation: 393

modify a property of a component through a controller in emberJS

I wonder if I can modify a property that is in a component via an external controller.

That is, I have an injected component in index.html as follows: {{ button-feed }}

This component is used in many views.

This component has to be hidden as I get values in the controller, and what I really want is that since this controller, modify a property that hides or shows the button.

The component has the form:

App.ButtonComponent = Ember.Component.extend ({
   hideClass: false
});

The property hideClass is used to display or not the button. What I want is to modify this property but using a controller that does not belong to the component button.

I tried to access the property from outside the component, but it is impossible.

Upvotes: 0

Views: 215

Answers (1)

rog
rog

Reputation: 5361

You can pass parameters to your component like this:

{{button-feed hideClass=true}}
{{button-feed hideClass=false}}

Also, you could pass in a controller property too.

{{button-feed hideClass=controllerProperty}}

To answer your comment, you can set the controllerProperty by using the code below. Since controllerProperty is bound to the hideClass on your component, changing controllerProperty will change hideClass.

controller.set('controllerProperty', false);

You can read more about setting properties on a controller here.

Upvotes: 2

Related Questions