Rahul Patil

Rahul Patil

  • 1.4k
  • 177
  • 29.1k

How to call a function on edit button in angular?

Jan 22 2020 5:43 PM

My project angular version:

Angular CLI: 9.0.0-rc.7

I m working with grid and I want to edit a record. and call a function when press the button but console.log is not display?

partymastercomponent.ts

  1. import { Component, OnInit } from '@angular/core';  
  2. import { BackendService } from '../backend.service';  
  3.   
  4. @Component({  
  5.   selector: 'app-partymaster',  
  6.   templateUrl: './partymaster.component.html',  
  7.   styleUrls: ['./partymaster.component.css']  
  8. })  
  9. export class PartymasterComponent implements OnInit {  
  10.   
  11.     PartyMstId: any;  
  12.     PartyCode: any;  
  13.     PartyName: any;  
  14.   
  15.     partylist: any;  
  16.   
  17.     constructor(public myservice: BackendService) { }  
  18.   
  19.     columnDefs = [  
  20.       {  
  21.           headerName: "Edit",  
  22.           field: "icon",  
  23.           width: 100,  
  24.           //id: this.PartyMstId,  
  25.           cellRenderer: function (params)  
  26.           {  
  27.                         //return  '' //when i press edit icon then console log not print  
  28.                          return 'ClickThis' //when I press button then console.log is not display  
  29.           }  
  30.       },  
  31.       { headerName: 'PartyMstId', field: 'PartyMstId', sortable: true, filter: true/*, checkboxSelection: true*/ },  
  32.       { headerName: 'PartyCode', field: 'PartyCode', sortable: true, filter: true },  
  33.       { headerName: 'PartyName', field: 'PartyName', sortable: true, filter: true },  
  34.   
  35.  ];  
  36.   
  37.   editfunction() {  
  38.       console.log("call this edit function");  
  39.   }  
  40. }  
partymastercomponent.html
  1. <ag-grid-angular style="width: 1000px; height: 500px;"  
  2. class="ag-theme-balham"  
  3. [rowData]="partylist"  
  4. rowSelection="multiple"  
  5. [columnDefs]="columnDefs">  
  6. </ag-grid-angular>  
how to call a function on edit button click??
 
icon as well as button is not working??
 
when I press right click on browser then
  1. <span><button(click)="editfunction()"><i class="fa fa-edit"></li></button></span>  
help??

Answers (9)