Functions defined on a property of a controller can be invoked from view expressions or in response to events. As a general pattern, view paths refer to the model when getting values and to the controller when calling functions.

Functions are looked up on the current component's controller, the page, and the global, in that order. See the view functions and events documentation for more detail.

ANCHORCustom events

Components support custom events. Dashes are transformed into camelCase.

<modal on-close="reset()" on-full-view="back.fade()"></modal>
// Equivalent to:
modal.on('close', function() {
modal.on('fullView', function() {

ANCHOREmitting events

Components can emit custom events to be handled by their parents.

  <modal on-full-view="back.fade()"></modal>
  modal.on('fullView', function(foo) {
  modal.emit("fullView", foo);

ANCHORCalling peer component methods

Components and elements can be set as a property on the current controller with the as= HTML attribute (more detail). This paired with how controller properties are looked up on function calls makes it easy to connect events on components or elements to methods on other components.

<!-- Connecting an instance of a component to an event -->
<modal as="modal"></modal>
<button on-click=""></button>
<!-- `page` is available on all controllers, even in separate components -->
<flash as="page.flash"></flash>
<button on-click="'Clicked')"></button>

ANCHORComponent event arguments

Component events implicitly pass through any emitted arguments. These arguments are added after any explicitly specified arguments in the expression.

<!-- Will log any arguments emitted by the submit event -->
<dropdown on-submit="console.log()"></dropdown>
<!-- Will log 'dropdown' followed by any emitted arguments -->
<dropdown on-submit="console.log('dropdown')"></dropdown>
Edit on GitHub