最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Aurelia: How to call a function outside custom element? - Stack Overflow

programmeradmin5浏览0评论

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

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?

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

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?

Share Improve this question edited Oct 12, 2016 at 22:47 Jeremy Danyow 26.4k12 gold badges90 silver badges135 bronze badges asked Dec 28, 2015 at 8:37 Chu Văn NamChu Văn Nam 1212 silver badges5 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 22

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>
export class A {
  updateDescription = () => {
  };
}

Then

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

inside CustomElem call this.onCompleted()

发布评论

评论列表(0)

  1. 暂无评论