I'm seeing this feature in the docs, but I can't quite figure out how to use it from that information.
It says:
<i-produce-a-value ref.view-model="producer"></i-produce-a-value>
<i-consume-a-value input.bind="producer.output"></i-consume-a-value>
What does this look like in real world example?
This syntax has actually changed to be more consistent with the rest of Aurelia's binding syntax in our latest release (which hit after you posted this question).
The syntax is now:
But anyways,
view-model.ref="producer"creates an alias to the view-model for thei-produce-a-valuecustom element which you can then use elsewhere to pass to another custom element or use properties of the VM. Thus in the second line of the code above,i-consume-a-valuehas a property calledinputthat has been bound to theoutputproperty of the VM of thei-produce-a-valueelement.Let's look at an example. Say you have a
DatePickercustom element. Its view model has several properties such asdayOfWeekandmonth. You would like to use the properties in other elements on your view. You could bind a property on your View's VM to each of these properties and then bind to your View's properties elsewhere in your view where you want to use these values, or you can use theview-model.refto allow you to bind directly to these values on yourDatePickercustom element. Something like this:So, in this example, we have bound the value property of the
DatePickerto theeventDateproperty of our page's VM. More importantly, we have created an alias to the VM of theDatePickercustom element and named iteventDateVM. We then use this alias to display the month and day of week for the date picked in the custom element. This imaginaryDatePickeralso has a VM property that is set to the url for a picture of something that happened on the date chosen, so we bind that url to thesrcproperty of animgtag.Let me know if you have any more questions about this very powerful feature of Aurelia!