Aurelia: How to call a function outside of a user element?

I have one custom element called custom-element and I put it in template A (with controller A)

custom-element

export class CustomElem { @bindable onCompleted; ........ } 

And updateDescription () is one of the functions of controller A.

 export class A { updateDescription(){ .... } } 

How to call updateDescription () using a custom element?

+8
javascript aurelia
source share
2 answers

Use the call bind command to give a link to a function call to your user element:

 <custom-element on-completed.call="updateDescription()"></custom-element> 

To call the updateDescription method with arguments, you can do the following:

 export class CustomElem { @bindable onCompleted; ... fooBarBaz() { var args = { something: 'A', somethingElse: 'B', anotherArg: 'C' }; this.onCompleted(args); } } 
 <custom-element on-completed.call="updateDescription(something, somethingElse, anotherArg)"></custom-element> 
+19
source share
 export class A { updateDescription = () => { }; } 

Then

 <custom-element on-completed.bind="updateDescription"></custom-element> 

inside CustomElem call this.onCompleted()

+2
source share

All Articles