I am working and see an email come in from flexcoders asking how you would access a variables value in one component from another. Easy enough. Well, that is what I thought. I came up with three different answers to this problem and I am convinced there are others. All good enough, but which is best to implement. I will let you decide.
1. Put bindable public variables (properties) on your components and set the values in the parent.
2. Dispatch an event on one component and have the parent component set the other components property.
3. Create a singleton class that holds the values and bind the data to your components, so when there is a change, the values in the components will be set accordingly.
I like the third answer best, but is a bit overkill for the simple implementation that does not need to access the information more than once. The third has more scalability, but takes longer to code.
Demo Example
Source Code
Which would you use? I think it is based on your needs.
Currently rated 3.2 by 11 people
- Currently 3.181818/5 Stars.
- 1
- 2
- 3
- 4
- 5