简体   繁体   中英

Angular function that does task I can not figure out why it is this function

I have a sample code that is written in angular/node. I pin pointed the function that performs a task. I can not figure out why..or how.

I was able to go through the snippets of code and pin point the record by adding a console.log() and logging out the data so I know the function i found is the correct one i just dont undestand why because in angular it is called "delete()" but in the function it is called "deleteValue()"

This is the angular as you can see the delete(row._id) is the onclick function that gets called.

<div class="card-body">
  <ngx-datatable class='material' *ngIf="row"  [columnMode]="'force'" 
                 [headerHeight]="40"  [footerHeight]="40" [rowHeight]="'50'" 
                 [limit]="500000" [rows]='perm' [scrollbarH]="true"
                 #table [limit]="_limit" >
    <ngx-datatable-column prop="value" name="Name" [width]="130" 
                          [sortable]="true">
      <ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
        {{row.value}}
      </ng-template>
    </ngx-datatable-column>
    <ngx-datatable-column prop="qty" name="Qty" [width]="130"             
                          [sortable]="true">
      <ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
        {{row.qty}}
      </ng-template>
    </ngx-datatable-column>

    <ngx-datatable-column name="Action" [sortable]="false" [width]="75">
      <ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
        <div class="justify-content-center align-items-center">
          <span class="col-md-4">
            <button class="btn btn-danger" (click)="delete(row._id)">
              Delete
            </button>
          </span>
        </div>
      </ng-template>
    </ngx-datatable-column>
  </ngx-datatable>
</div>

This is the nodejs code:

valueController.deleteValue= async (req)=>{
  try{
    var recordType = await valueModel.deleteValue({_id: req.params.id});
    console.log('Deleting record: ' + req.params.id);
    return recordType;
  } catch(error) {
    throw error;
  }
}

Thanks,

I was expecting the function to be called delete not deleteValue how does this work?

(click)="delete(row._id)"

Will call a method called delete on the Angular component, we cannot see your Angular TypeScript here but the component would then normally then call an Angular service and that service would then make a http call to your node api.

The click function on a button is not going to directly call the api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM