Replacement for call binding in Aurelia 2

After updating to beta version, I started to have exceptions related to call bindings:

<pager changed.call="pageChanged()"><pager>
Error: AUR0713: Unknown binding command: call

I have seen that the call binding has been moved to the package @aurelia/compact-v1. From my understanding, this package is just for migration purpose and the call binding has been deprecated.
Is it correct?

After some tests I have found that in Aurelia 2 the call binding can be replaced by binding to arrow function:

<pager changed.bind="() => pageChanged()"></pager>

With this binding the pageChanged function executes on the right context for this.

Is it right? How can I pass events arguments in this case?

Hi @ernstc ,

According to the migration documents:
Migrating to Aurelia 2 - The Aurelia 2 Docs

Aurelia 1
<my-element on-change.call="propertyChanged(value)">

In Aurelia 2, the property name is now on the $event property passed to the callback. It’s a minor change, but you now do this instead:

<my-element on-change.call="propertyChanged($event.value)">

Hi @mroeling,
thanks for your reply, but I am not migrating an application from v1 to v2.
I am starting a new application and I would like to use only Aurelia 2 without the migration library @aurelia/compact-v1.

Since the call binding has been removed from Aurelia 2, I think that in the documentation is missing how to manage custom element callbacks (or events) in the proper way.

Understood. It was not from a migration point of view, but I remembered to have read it in those documents.
It’s in the normal documentation as well:

1 Like

Hi @mroeling, you answered my question.

Anyway I still feel confused reading the documentation because it says that .call has been deprecated but not already removed. It’s not clear that for using it you need the @aurelia/compact-v1 package until you go to the migration documentation, and even reading that I did not understood that the package is required for using .call because it focuses on the changes about the management of the $event passed to the callback function.

For resolving the compilation error AUR0713 I needed to check the differences in the source code between the beta and the last alpha :slight_smile:

Anyway, thank you for the support. I will read the docs with more attention.

2 Likes

The messages around the removed binding command have been enhanced in DEV dist. you can see in this commit chore(doc): better dev message for missing delegate and call binding … · aurelia/aurelia@cb0f646 · GitHub

Indeed the DEV messages should have been better, thanks @ernstc @mroeling

3 Likes