2

I want to create a button in typescript file using the html tags.I don't know how to add click event for that button i have created 2 action buttons wat to add the click event

"data": "img", "render": function (data) {
    return '<button class="btn tblActnBtn" value= "Click" id="edit" (click)="onClickMe()" ><i class="material-icons">mode_edit</i></button><button class="btn tblActnBtn"><i class="material-icons">delete</i></button>'
}

Thanks,

1
  • Why are you creating a button it .ts and not in .html? You can change the value with interpolation. Please describe carefully your problem. Commented Feb 7, 2020 at 15:24

2 Answers 2

1

html :

<div  [innerHTML]="answerPanelContent"></div>

ts:

import { Component, Renderer2, ElementRef, OnInit } from '@angular/core';
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  implements OnInit {
  constructor(    private renderer:Renderer2,
                  private el:ElementRef) { }

  ngOnInit() {
    const button = this.renderer.createElement('button');
    const buttonText = this.renderer.createText('Click me');
    this.renderer.appendChild(button, buttonText);
    this.renderer.appendChild(this.el.nativeElement, button);
    this.renderer.listen(button, 'click', () => {alert('hi');});
  }
}

you can write every event in {alert('hi');......}

Sign up to request clarification or add additional context in comments.

Comments

0
self.testTable.on('click', 'input', function () {

  var tr = $(this).closest('tr');

  var row = self.testTable.row(tr);

  var id = this.id;

  var data = self.testTable.row(tr).data();

  if (id == 'check') {

   console.log("****",row.data())

  }

});

It works for me.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.