Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aurelia: How to call a function outside custom element?

I have one custom element named custom-element and I put it inside template A (with controller A)

custom-element

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

And updateDescription() is one function of controller A.

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

How to call updateDescription() by using custom-element?

like image 535
Chu Văn Nam Avatar asked Dec 28 '15 08:12

Chu Văn Nam


Video Answer


1 Answers

Use the call binding command to give a reference to a function call to your custom 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>
like image 139
Jeremy Danyow Avatar answered Sep 28 '22 05:09

Jeremy Danyow