简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM