title: Unable to call Angular 6 Service from HTML EventListener
body: <p>I have an angular ag-grid, from where I have created a cellRenderer and cellRendererParams. And from cellRenderer I am calling a method which creates a button in that every cell of ag-grid.</p>
  
  <pre><code>constructor(private notificationService: NotificationService) { }
  
  ngOnInit() {
      this.columnDefs = [{
              headerName: "Action",
              field: "notificationId",
              width: 180,
              cellRenderer: this.notificationCellRendererFunc,
              cellRendererParams: {
                notificationId: 'notificationId'
              }
            }];
  }
  </code></pre>
  
  <p>And the notificationCellRendererFunc:</p>
  
  <pre><code>notificationCellRendererFunc(params) {
      var self = this;
      var eSpan = document.createElement('button');
      console.log(params.value); // logs notificationId
      eSpan.innerHTML = 'Resend';
      eSpan.id = params.value;
      eSpan.addEventListener('click', function (eSpan) {
        alert(eSpan.toElement.id);
        var notificationFilter: any = {};
        notificationFilter.notificationId = eSpan.toElement.id;
        self.notificationService.ResendNotification(notificationFilter)
          .subscribe(
            (data: any) =&gt; {
              console.log('in save')
            },
            err =&gt; { console.log(err) }, // error
        );
  
      });
      return eSpan;
    }
  </code></pre>
  
  <p>In the above method, I am creating eventListener for every button, so that when any of the button hits, it will provide me the selected row's notificationId and I can send it to the API for further processing.</p>
  
  <p>But the problem is, 'this' keyword is not working inside eventListener, even if I assign 'this' to 'self' keyword outside the listener. It says: 
  <strong>ERROR TypeError: Cannot read property 'notificationService' of undefined
      at HTMLButtonElement.</strong>.</p>
  
  <p>"My moto is to create a button in every row of ag-grid, and after hitting the button it will resend the notification."</p>