Search code examples
dartdart-polymerangular-dartpaper-elements

How to pass event object from paper-button click to angular.dart's function?


I have am using paper-button for click event and trying to add on-click="angularComponent.function" where angularComponent.function is a function in a angular.dart's component within which this paper button is being used, but the click is not triggering the function call. However, with on-click="angularComponent.function('a','b','c')", it does trigger function on click (courtesy of angular_node_bind module). This means that I can't get hold of event object, which is otherwise passed to pure dart/polymer element function. How to get around this?


Solution

  • In Angular you usually pass $event to have the event object available in the handler

    @Component(
        selector: 'my-cmp',
        publishAs: 'cmp',
        template: r'<div><paper-button ng-click="cmp.clickHandler($event)" label="click me"></paper-button></div>'
    )
    class MyComponent {
      void clickHandler(dom.Event event) {
        print('clicked: $event');
      }
    }