【问题标题】:Delete method with kendo-grid using angular and sweetalert2使用 angular 和 sweetalert2 的 kendo-grid 删除方法
【发布时间】:2019-10-08 07:39:24
【问题描述】:

我的问题是在我尝试绑定数据后它没有做任何事情需要执行该方法。 它只弹出sweetalert,但是当我单击两个按钮时,什么也没有发生。 有什么解决方案/指南吗?

我使用一个api来执行在本地运行的方法。

HTML

<kendo-grid
    [kendoGridBinding]="prod"
    [filterable]="true"
    [groupable]="true"
    [sortable]="true"
    [pageSize]="10"
    [pageable]="true"
    [height]="510">
    <kendo-grid-column field="productId" title="Product ID" [width]="70"></kendo-grid-column>
    <kendo-grid-column field="productName" title="Product Name" [width]="120"></kendo-grid-column>
    <kendo-grid-column field="productNumber" [width]="100"></kendo-grid-column>
    <kendo-grid-column field="description" [width]="130"></kendo-grid-column>
    <kendo-grid-column title="command" width="100">
            <ng-template kendoGridCellTemplate let-dataItem>
                <button kendoGridEditCommand [primary]="true">Edit</button>
                <button
                  [swal]="{ title: 'Delete Product', 
                            text: 'this will delete permanently',
                            cancelButtonColor:'#d33',
                            showCancelButton:true,
                            cancelButtonText:'Cancel',
                            confirmButtonColor:'#000000',
                            confirmButtonText:'Delete'}"
                  (confirm)="deleteProduct(dataItem.productId)">
                  Delete
                </button>
            </ng-template>
    </kendo-grid-column>
</kendo-grid>

组件.ts

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './product-list.component.html',
  styleUrls: ['./product-list.component.css']
})
@Injectable()
export class ProductListComponent implements OnInit {

  constructor(private http:HttpClient) {}

  prod : any;

  ngOnInit() {
    this.listProduct();
  }

  getProduct(){
    return this.http.get("http://localhost:51024/api/Product/GetAllProduct");
  }

  listProduct() {
    this.getProduct().subscribe((data) => this.prod=data);
  }

  public deleteProduct(productId: number): void {
    this.http.delete("http://localhost:51024/api/Product/"+productId);
  }
}

【问题讨论】:

    标签: angular kendo-ui kendo-grid kendo-ui-angular2


    【解决方案1】:

    我认为您需要订阅删除。否则不执行。

    public deleteProduct(productId: number): void {
       this.http.delete("http://localhost:51024/api/Product/"+productId)
       .subscribe(response => ...);
    }
    

    【讨论】:

    • 这很好用,谢谢:D,但即使状态为 200,它也会返回 HttpErrorResponse,我必须重新加载才能看到更改。再次感谢。
    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2015-12-15
    相关资源
    最近更新 更多