Disabling click events on a span tag in Angular 6: A step-by-step guide

Is there a way to disable the click event for deleting hours with the 'X' symbol based on a condition? Thank you in advance.

<table navigatable class="<some_class>">
    <tbody>
        <tr *ngFor="let item of list; let i=index">
            <td style="width: 95%">{{item}}</td>
            <td style="width: 5%">
                <span class="<some_class>" (click)="DeleteHour(i)">X</span>
            </td>
        </tr>
    </tbody>
</table>

https://i.sstatic.net/OEnO7.png

Answer №1

To prevent the action, you could implement an "early return" in the DeleteHour(i) function.

const DeleteHour = (i) => {
  if (isDisabled(list[i])) return;
  // ...remainder of the code
}

If by "disable visually" you mean changing a visual aspect when disabled, you can achieve this with the following approach:

<span class="<some_class>" (click)="DeleteHour(i)">{{ isDisabled(item) ? '🚫' : 'X' }}</span>

Alternatively, you may consider using a button and applying the CSS pseudo-class

delete-hour:disabled { ...styles }
:

<button class="delete-hour" (click)="DeleteHour(i)" [disabled]="isDisabled(item)">X</button>

Answer №2

Here's a suggestion with some modifications to your HTML:

function DeleteHour(e){
e.parentNode.style.display = "none";
  e.parentNode.previousElementSibling.style.display="none";
}
<table navigatable class="<some_class>">
    <tbody>
        <tr *ngFor="let item of list; let i=index">
            <td style="width: 95%">{{item}}</td>
            <td style="width: 5%">
                <span class="<some_class>" onclick="DeleteHour(this)">X</span>
              
                          <td style="width: 95%">{{item}}</td>
            <td style="width: 5%">
                <span class="<some_class>" onclick="DeleteHour(this)">X</span>
              
                          <td style="width: 95%">{{item}}</td>
            <td style="width: 5%">
                <span class="<some_class>" onclick="DeleteHour(this)">X</span>
            </td>
        </tr>
    </tbody>
</table>

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

IE not rendering 'right' property in jqueryui CSS

I am attempting to shift a neighboring element after resizing a text area, triggered by the stop event on jqueryUI's resizable feature: $("textarea").resizable({ stop: function (event, ui) { var x = ui.originalElement.closest("li").find(" ...

Is there a way to access VMWare localhost on a mobile device?

Currently, I am utilizing VM Ware for my development tasks and I am working on creating some responsive design code. Instead of using the web-developer tools' responsive layout emulator, I would like to view it in action on my mobile device. I am look ...

What sets apart :host::ng-deep .class from .class :host::ng-deep?

Can you explain the distinction between the following two lines of code in scss, Provide some sample snippets as examples. :host::ng-deep .content-body { ... } and .content-body :host::ng-deep { ... } ...

Datagrid in AngularJS does not update filters upon refresh

Currently, I am attempting to implement name filtering with Angular JS using the following library: https://github.com/angular-data-grid/angular-data-grid.github.io. However, an issue arises when searching as the results do not refresh immediately; only up ...

Customizing JqGrid to include a button in the advanced search dialog

I am interested in enhancing the advanced search dialog to include a feature that allows users to save a complex query they have built. Although saving the SQL code is not an issue, I need guidance on integrating buttons within the advanced search query d ...

Struggling to line up three images with linked attachments in a single row using Bootstrap 4

Currently tackling my portfolio for a school project, I find myself stuck on organizing my projects in a single line. Here is the code snippet that's giving me trouble... <div class="container"> <div class="row"> <div class= ...

The bootstrap 4 modal is not displaying the button as expected

I am currently working on an Angular 4 project and I am trying to implement a pop-up using Bootstrap 4. <div> <span class="text-center" id="span1">{{title}}</span> <button type="button" class="btn primary-btn" data-toggle="modal" data ...

No data appearing in the console after sending a POST request using Node.js

Is anyone else experiencing issues with retrieving data in the post request below? I'm open to suggestions. var bodyParser = require('body-parser'); var jsonParser = bodyParser.json(); var urlEncodedParser = bodyParser.urlencoded({extende ...

Retrieve a distinct property of an element from an array of objects fetched from an API using Vue 2

I successfully retrieved an array of objects from an API in mounted within Vue. The array consists of various objects with properties such as author, genre, poster, title, and year. 0: author: (...) genre: ("Rock") poster: (...) title: (...) year: (...) 1 ...

Adding a new data source to Mapbox

When working with mapbox, I encountered a 404 error while trying to load a layer from a variable geojson. The addSource data function always expects the data to be a URL. Is there a way to use variables instead? this.map.on('load', () => { c ...

Looking for a way to access the source code of a QML method in C++?

I'm currently working on serializing objects to QML and I am looking for a way to retrieve the source code of functions defined within a QML object. Let's consider the following example in QML (test.qml): import QtQml 2.2 QtObject { functio ...

Can you identify the specific name of the IE CSS bug affecting double vertical padding?

(Just when I thought I've encountered all the strange IE CSS bugs, here comes another one. Is there a name for this double-vertical-padding bug?) After creating a simple test case that worked perfectly in browsers like FF and Opera, I was surprised t ...

What is the best way to extract fields from one object and merge them into another object using Javascript?

Here is the scenario: $scope.book1 = { a = 1, b = 2 } This is the information retrieved from the database: $scope.book2 = { title = 2, author = 'joe' } What steps should I take to merge the data in book2 into book1, ensuring that all ...

JavaScript counter that starts at 1 and increments with each rotation

I am working with an array of image IDs. let images = ['238239', '389943', '989238', ... ]; let max = images.length; The array begins at index 0 and its size may vary. For instance, if there are 5 images in the array, the i ...

Creating a dynamic layout of 9 divs in a fluid 3x3 grid

Fiddle | FullScreen UPDATE : New Fiddle | FullScreen View The code snippet provided demonstrates the creation of a grid with dimensions of 3x3, consisting of 9 div elements (with 8 cloned using jQuery). The horizontal alignment of the grid has been ac ...

Personalize the Facebook like button to suit your preferences

I have posted my code on jsfiddle. You can find the link here: http://jsfiddle.net/QWAYE/1/. I have also included another sample code in this link: http://jsfiddle.net/MCb5K/. The first link is functioning correctly for me, but I want to achieve the same a ...

Knitting: exporting to HTML file while retaining formatting

Recently discovered the amazing knitr library in R, which looks great when viewed in the viewer. But unfortunately, the style gets lost when saved to an html file. Code library(knitr) library(kableExtra) some.table <- data.frame ( x = rep(1 ...

Choose the CSS class based on the content provided

Help needed with CSS issue. I want to target the <tr> element's class using Bootstrap classes like .success or .danger. In my Vue.js project, the status name in my object does not align with the .success or .danger classes, but I still need to ...

accessing a webpage using an ionic application

I currently have a responsive website, but I am looking to turn it into an app in order to utilize push notifications. Right now, I am using the inappbrowser plugin to open my website with this code: <a href="#" onclick="window.open('http://www.ex ...

How to retrieve the value instead of the key/ID in a Laravel controller?

I am extracting data from the database and displaying it on the invoice view page using the json_encode($items); function. When I try to insert the 'price' field into the database, only the id/key is being stored instead of the actual value. Any ...