Provide callback for custom component

I created a custom component that basically wraps a d3 line chart. Now I want to be able to register a callback for clicks on the rows in the diagram.

I gave the component a @NgCallbackparameter, which then dispatches events:

class NetworkSummaryComponent implements NgShadowRootAware {
  @NgCallback('callback')
  Function callback;

  void onShadowRoot(ShadowRoot shadowRoot) {
    ...
    chart.callMethod('listen', ['line-click', (ev) {
        var name = ev.callMethod('getLineName');
        print(name);
        callback({'name': name});
    }]);
  }
}

When using the component, I define the function of my controller as a callback:

<network-summary
    ...
    callback="ctrl.lineClicked">
</network-summary>

However, this function is never called, I suppose I know that the callback comes from JS because it prints in the first fragment.

If you instead specify the attribute as callback="ctrl.lineClicked()", I get a strange exception:

Closure call with mismatched arguments: function 'call'

I could not find the official documentation on how to make callbacks correctly, so I'm not quite sure what I'm doing wrong. Any ideas?

+4
1

, :

<network-summary
    ...
    callback="ctrl.lineClicked(name)">
</network-summary>

, , .

+7

Source: https://habr.com/ru/post/1535388/


All Articles