A guide on integrating a data deletion feature in Angular applications

On our website's edit page, there is a list of mat cards/workspaces with an edit icon in the top corner of each workspace. Clicking on the edit icon will take you to the edit page for that specific workspace. Within this edit page, there is a delete button that triggers a dialog box prompting the user to confirm if they want to delete the workspace.

I am currently unsure about what needs to be done for the API call.

.name.length > 0 && this.description.length > 0) {
      // Mapping data to workspace object
      this.workspace.name = this.name;
      this.workspace.description = this.description;
      this.workspace.type = WorkspaceType.public; // All workspaces are public by default

      // Creating new workspace
      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);

    }

Answer №1

If you're looking to implement a similar functionality, consider the following approach:

openModalConfirmationDialog(message: TemplateRef<any>, row, progressTemplate: TemplateRef<any>, successTemplate: TemplateRef<any>) {
// Save the selected data until the page is active
  this.rowToDelete = row;
// Display the confirmation dialog
    this.modalService.open(message).then(result => {
        if (result) {
            // Open progress dialog
            this.modalService.open(progressTemplate);
            // Call custom function to delete data
            this.deleteDataAPIFunction('/name1/requestedWorkspaceDelete', row.id, successTemplate);
        }
    });
}

deleteDataAPIFunction(url, param, messageTemplate: TemplateRef<any>) { 
// Display success or error messages based on deletion outcome
 this.http.get(baseUrl + url, options)
        .subscribe(response => {
                if (response != null) {
                   // Success message for delete operation
                } else {
                    // Error message for failed delete operation
                }
            }

}

Add this code to your HTML delete button event:

(click)="openModalConfirmationDialog(confirmDialog, row, deletionInProgress, deletionSuccess)"

The above function references dialogs that are passed as parameters:

<ng-template #confirmDialog>
    <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 #deletionInProgress>
    <custom-directive type="warning" warningTitle="Deletion in progress">
    </custom-directive>
</ng-template>

 <ng-template #deletionSuccess>
    <custom-directive type="success" successTitle="Success" btn="Close">
        <div>Workspace ID: {{workspace.id}} has been deleted</div>
    </custom-directive>
</ng-template>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to invoke a JavaScript function within a child window that is already open

I am working on a project where I have a main html file. In this file, I want the user to click on something that will trigger a new window or tab to open. This new window/tab should display the dynamically generated content of a hidden div in the main htm ...

When an HTML email is sent from the Outlook 2007 Exchange server, it may appear as plain text when viewed on

After extensive searching, I've come across two old threads with unanswered questions on this topic. In our office, we have a Windows XP PC designated for "production" that sends out emails in HTML format. These emails contain multiple excel Cells for ...

What is the best method to retrieve child elements from a class list object?

Seems like I have a similar content class <div class="parentclass"> <div class="childClass"> </div> <div class="childClass"> </div> <div class="childClass"> </d ...

Seeking a sleeker approach to composing various components with shared functions

Currently, I have a scenario where I have identical components that display data but also need to handle state manipulation and saving. There are 5 other similar components with slight differences in their functions. I am looking for a more efficient way t ...

The hideCol method does not work on jqGrid

Encountering a problem with the hidecol method in jqGrid. Despite calling the method, nothing seems to happen. Using version 4.5 of jqGrid. The table is created as follows: // Table creation using jqGrid $('#shipTable').jqGrid({ data: tabl ...

Ways to align the content in the middle of a div with CSS

My website is functioning perfectly on large devices, but I am facing an issue when trying to center the icon below the slider on mobile devices. I have used the following code in the icn class: .icn{ margin:0 auto; } However, the icon is not centered as ...

Transferring information from a chosen <mat-option> to a different component in Angular Material

I am currently facing an issue with two components in my Angular application. The first component includes an Angular Material mat-option to select an option from a dropdown menu, while the second component is supposed to display the selected data. I attem ...

The issue of losing context when using Papaparse with an Angular 4 function

Check out this block of code httpcsv2Array(event) { var gethttpcsv = Papa.parse('https://docs.google.com/spreadsheets/d/e/yadyada/pub?output=csv', { download: true, header: true, ...

I want to locate every child that appears after the <body> element, and extract the HTML of the element containing a specific class within it

It may sound a bit confusing at first, but essentially I have some dynamically generated HTML that resembles the following: <body> <div class="component" id="465a496s5498"> <div class="a-container"> <div class="random-div"> ...

Angular 6 and Typescript: How to Map Objects in Arrays within Arrays

We currently have two arrays named speisekarte (consisting of 10 objects) and essensplan (containing 8 objects). const speisekarte = [ { id: 11, name: 'Kabeljaufilet', price: 3.55, type: 'with fish' }, { id: 12, name: 'Spaghet ...

Is it possible to integrate Symfony, Node.js, and Angular into a single application?

Hey there, I am currently working on an audit platform for applications developed using Angular, Node.js, and Symfony. I was wondering if it is possible to use all three technologies simultaneously. You can check out my project in the link below. Thank you ...

Adding graphs dynamically to Dygraphs allows for real-time updates and interactive data

I recently started using Dygraphs for one of my projects and I am still learning how to work with it. After reading through the documentation and looking at a few examples, I noticed that the constructor for Dygraphs requires a div element where the graph ...

Ways to align the contents of a div in the center

Looking at the content in this div, it seems that the top is positioned higher than the bottom. Can anyone provide some guidance on how to fix this? .dtestContactDet{ border-bottom:1px solid #D7D7DE; border-bottom:1px solid #D7D7DE ; -khtml-border-bo ...

Using a .NET Web-API controller variable as a parameter in a JavaScript function

I am looking to send a "variable" from the controller to a JavaScript function. The code I have implemented is as below: <div ng-controller="faqController"> <div ng-repeat="c in categories"> <h2 onclick="toggle_visibility(&apos ...

Font Awesome solely alters the font size within html, rather than css

<i class="fa fa-graduation-cap" aria-hidden="true" style="font-size: 50px;"></i> It's functioning properly. .fa-graduation-cap { margin-top: 38px; color: #E46A6B; font-size: 50px; } Not working too well. This issue is new to me. Any th ...

Ways of invoking a component method from a service in Angular 2

I have a concept for creating a unique service that is capable of interacting with one specific component. In my application, all other components should have the ability to call upon this service and then have it interact with the designated component in ...

What is the best way to apply styles to a React component that is passed as a prop?

I'm currently working on a component that is passed as a label prop. In order for me to utilize justify-content: space between within my div, I must ensure it has a width of 100%. You can see how this appears in the developer tools by clicking here. r ...

Handling the width and borders of CSS cells that are positioned outside of a table

Welcome! I recently created a simple gantt organizer as part of a demo. My goal was to make the main table scrollable while keeping certain columns "frozen" for easy visibility when navigating through the data. To achieve this, I followed some advice found ...

Removing a data entry from a PHP-generated MySQL table

In the process of developing a system, I have encountered a need to display database records in an HTML table. The functionality for creating the HTML table and retrieving data is working as expected. However, I am facing an issue with adding a column cont ...

Angular 6: Simplify Your Navigation with Step Navigation

Can someone please assist me with configuring a navigation step? I tried using viewchild without success and also attempted to create a function with an index++ for three components on the same page. However, I am unable to achieve the desired outcome. Any ...