peerlibrary / meteor-blaze-components

Reusable components for Blaze
http://components.meteorapp.com/
BSD 3-Clause "New" or "Revised" License
354 stars 26 forks source link

How to access component method outside of component? #91

Closed kokjinsam closed 9 years ago

kokjinsam commented 9 years ago

Hi,

I have been exploring this awesome package for two weeks now. It's awesome! Thanks for your hard work!

Due to the fact I'm still new to this package, please excuse my noobiness. How do I access a component method outside of the component? For example, I have a hide() function in headerComponent and I want to use the hide function from contentComponent. How do I do that?

and if I want to use the hide function from a non BC, how should I do that?

mitar commented 9 years ago

You should traverse the tree of components using childrenComponents or parentComponent methods (possibly calling it recursively), finding the component you want, and calling a method on it.

Where exactly you want to call it from outside a component? In general you simply have to have a reference to the component. You can store it somewhere, for example. You can also use getComponentForElement to get a component from a DOM element.

See also #81 and #82.