Ways to prevent clicking on ng-repeat rows?

Is it possible to prevent clicking on ng-repeat rows? How can I achieve this?

Below is a sample code snippet:

<div ng-controller="MyCtrl" class="grid">
  <div class="header">
    <div class="cell">Id</div>
    <div class="cell">Name</div>
  </div>
  <div class="gridBody">
    <div ng-class-even="'even'"
         ng-class-odd="'odd'"
         ng-class="{current: row.current == true}"
         ng-click="clicked(row)"
         ng-repeat="row in topics" class="row"
         ng-disabled="disabled == true">
      <div class="cell">{{row.id}}</div>
      <div class="cell">{{row.name}}</div>
      <div class="cell">{{row.current}}</div>
    </div>
  </div>
</div>

A jsfiddle has also been created to demonstrate the issue at hand.

Updates:

The jsfiddle link has been modified to provide more clarity on the problem I am facing. Hopefully, it helps in understanding my challenge better.

http://jsfiddle.net/2jxea6qw/8/

Answer №1

To achieve this functionality, create a custom directive and trigger an event capture.

Implement the subscription to the $element during the link phase of your ClickDisablerDirective in the following manner:

$element.addEventListener("click", function(e) {
   e.stopPropagation()
   e.preventDefault()
}, true)

Note that the 'true' parameter is crucial as it ensures the handler receives notification before any other lower level (bubbling wise) handlers.

Below is the complete directive implementation:

myApp.directive('disableClick', [function() {
 return {
    restrict:'A',
    link: function(scope, element) {
      element[0].addEventListener("click", function(e) {
        e.stopPropagation()
        e.preventDefault()
      }, true)
    }
 }
}])

I have updated the fiddle to demonstrate how it works: http://jsfiddle.net/2jxea6qw/6/

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

Automatically filling in related information in multiple input fields after choosing a value in a specific input field using JavaScript

My horizontal form is dynamically generated using JavaScript, with each input field having a jQuery autocomplete that retrieves data from a database using the $.get method. I'm looking to automatically populate the second input field with the corresp ...

Best Strategies for Dashboard Development using Angular JS

I'm diving into the world of Angular JS and tackling the task of building an Angular JS powered dashboard within a larger Django application. Despite my research on Angular, I still have lingering questions about the optimal way to structure an Angula ...

Issues with the functionality of the AngularJS button directive

Currently, I am working on developing a RESTful API utilizing Angular and NodeJS. However, I have encountered an issue where a button to navigate to the details page of my application is unresponsive. While I believe the button itself is correctly coded, I ...

What could possibly be causing the issue of $injector not being defined?

Encountering the following issue: Uncaught ReferenceError: $injector is not defined This error appears in the browser console. Below is how I have implemented it in my controller: (function () { 'use strict'; angular.module('DIApp&a ...

Angular4 - prevent form submission when input is empty or value is less than 1

Currently, I am validating forms in an angular project and everything is working correctly. However, I want to take it a step further by disabling the form when the value in a specific textfield noWards is less than 1 Text Field <input autocomplete="o ...

What is a Creative Name for a Javascript Array?

Can I assign a random number as the name of an array, in theory? var arrayname = "foo"; (the contents of arrayname) = ["1", "2", "3"] Is it feasible to do this? ...

Are there any SVG libraries available that can create line graphs similar to those seen in Google Analytics?

The line graph in Google Analytics that is created using SVG is quite impressive. Are there any libraries available that can generate similar line graphs to those in Google Analytics? ...

Secure access with Express/Node.js in the mobile app powered by Appgyver Supersonic

I find myself facing a bright shine of ignorance on this particular issue. The Web App I am working on utilizes the MEAN stack - Mongo, Express, Angularjs, Nodejs. However, I have noticed that some functionalities are not as optimal on mobile devices. As a ...

What is the reason behind $(this).text() returning an empty string when clicking on an li element?

Can anyone explain why clicking on this element returns a blank string ""? function saveSelection() { var selectedValue = $(this).text(); // The value here is "" } This pertains to: <ul> <li data-bind="item" onclick="saveSelection();"> ...

Ways to gradually adjust the height of a Div element

Is there a way to smoothly reveal a Div when scrolling down and clicking on a button? Currently, it seems to just appear quickly without any sliding effect. What could be causing this issue? function showstuff(inquiryForm){ document.getElementById(inq ...

Identifying a button element with AngularJS in a Selenium test suite

Looking to identify specific buttons within an angularjs context, the given HTML code presents a challenge. How can I differentiate these buttons using selenium? While my automation tool of choice is robotframework, any assistance in uniquely identifying t ...

Error message in Angular about undefined JavaScript function

Struggling to make my Angular 17 project functional with Bootstrap (5) and the datePicker feature. Despite following tutorials, I keep encountering a "ReferenceError: datePicker is not defined" error during the app build process. Here are the steps I&apos ...

Why is the PageLoad event triggering repeatedly because of the idletimeout plugin?

We encountered a peculiar problem on an asp.net web form project where the page was loading and displaying data (mainly in a gridview). A strange observation was made when setting a break point in the page load event of a specific page. After about 1-2 min ...

Find similarities between 2 observable arrays and store them in a new array using knockout data binding

There are three observable arrays set up as follows: a [1,3] b [ {"ID": 1, "Val": "Value1"}, {"ID":2, "Val":"Value2"}, {"ID":3, "Val":"Value3"}] c [] The goal is to compare array a with the IDs of elements in array b and then push the entire value of arr ...

Guide on setting up a new NPM and JavaScript project within Visual Studio 2015

Whenever I watch tutorials, they always mention having a "special npm reference" that I seem to be missing. https://i.sstatic.net/I52dn.png All I can find are the "normal" references (.net assemblies). I also can't locate any project type labeled as ...

The error "marker.setMap not a function" was not caught in the Google Maps API

Currently, I am creating a traffic jam application using MeteorJS 1.4.4.2 + ReactJS. Previously, I have utilized the atmosphere google map package and two popular Google Map npm packages (istarkov and tomchentw), which worked well but did not offer the spe ...

Running a JavaScript script after loading a page via AJAX is not functioning as expected

As I am attempting to retrieve a page using AJAX, I've encountered an issue where any Javascript code included on that page fails to execute. Why is this happening? The simple JavaScript code present in my ajax page is as follows: <script type=" ...

Tips for running a dry default with Angular CLI

Query: Can dry-run be set as the default in a configuration? Purpose: Enabling dry-run by default simplifies the learning process by minimizing clean-up tasks if the command is not correct. This can encourage users to always perform a test run before exec ...

JavaScript date selector allowing the selection of multiple dates

As a beginner in JavaScript, I am struggling to create a datepicker input field that allows multiple selections. Despite researching for solutions, none seem to fit my specific case. Can anyone offer guidance on how to achieve this? Your help is greatly ap ...

What is the best way to retrieve this value using javascript?

Currently, I am developing a browser extension for opera that will search for a specific element on the page when clicked. However, as a beginner in HTML and Javascript, I am completely lost and unsure of what steps to take next. The crucial value I need ...