亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Angular中實現數據刪除功能

如何在Angular中實現數據刪除功能

慕勒3428872 2023-10-24 21:31:22
在我們網站的編輯頁面中,我有一個墊卡/工作區列表,并且每個工作區的右上角都有編輯圖標。通過單擊該編輯圖標,您將進入該工作區的編輯頁面,其中有一個刪除按鈕,單擊該按鈕時會顯示一個對話框,并允許用戶決定是否確實要刪除該工作區。不太確定如何進行 API 調用 .name.length > 0 && this.description.length > 0) {      //map      this.workspace.name = this.name;      this.workspace.description = this.description;      this.workspace.type = WorkspaceType.public; //all workspaces that are created are public by default      //create      this.workspaceService.createWorkspace(this.workspace).subscribe(workspace => {        this.saving = false;        this.gotoManage();        this.snackbar.open(this.workspace.name+ " has been created!!", "", {duration :2500});      }, () => this.saving = false);    }  }
查看完整描述

1 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

你可以這樣做:


openModalConfirmationDialog(content1: TemplateRef<any>, row, content2:TemplateRef<any>, content3: TemplateRef<any>) {

// you can store row or data selected until page is active

  this.contetntIWantToDelete = row;

// Make availale data in popup for confirmation

    this.modalService.open(content1).then(result => {

        if (result) {

        // load the data (row) which is to be deleted

            this.modalService.open(content2);

        // update delete

     this.yourDeleteinfoAPIcustomFunction('/name1/requestedWorkspaceDelete', row.id, content3);

        }

    });

}


yourDeleteinfoAPIcustomFunction(url, param, content1: TemplateRef<any>) { 

// This function have success and error messages based on what is selected for deletion

 this.http.get(baseUrl + url, options)

        .subscribe(r => {

                if (r != null) {

                   // success delete operation

                } else {

                    // failed delete op.

                }

            }

}


在您的 html 刪除按鈕中:


(click)="openModalConfirmationDialog(modalConfirm, row, modalDeleteProgress, modalDeleteSuccess)"

在上面的函數中:我有一組在函數中傳遞的對話框,正如您提到的您想從對話框中獲得確認:


<ng-template #modalConfirm>

    <custom-directive>

        <p>Confirm delete operation</p>

        <p>Delete workspace Id: <B>{{workspace.id}}

            <br></B><B>{{moreDetails}}</B>

    </custom-directive>

</ng-template>


<ng-template #modalDeleteProgress>

    <custom-directive type="warning" warningTitle="Delete in progress">

    </custom-directive>

</ng-template>


 <ng-template #modalDeleteSuccess>

    <custom-directive type="success" successTitle="Success" btn="Close">

        <div>workspace ID: {{workspace.id}} has been deleted</div>

    </custom-directive>

</ng-template>


查看完整回答
反對 回復 2023-10-24
  • 1 回答
  • 0 關注
  • 161 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號