The ng-disabled directive appears to be malfunctioning

In my angular-based application, I have a controller that includes the following HTML code for implementing pagination.

<li class="{{(first) ? 'disabled' : ''}}">
    <a href="" ng-click="pageChange('first')" ng-disabled="first">First</a>
</li>

While the class is successfully applied to the li element, the ng-click directive does not disable the anchor as intended.

Answer №1

It is not possible to disable an a element.

According to http://www.w3.org/TR/html5/disabled-elements.html:

4.13 Disabled elements

An element is considered disabled if it falls into one of these categories:

- Button elements that are disabled

- Input elements that are disabled

- Select elements that are disabled

- Textarea elements that are disabled

- Optgroup elements with a disabled attribute

- Option elements that are disabled

- Fieldset elements with a disabled attribute

Most likely, you'll need to change the a element to a button and style it to appear like a link.

Here is a link to a fiddle demonstrating this: http://jsfiddle.net/simpulton/q8r4e/

Note that the fiddle does not belong to me, I found it through a search.

If you are using bootstrap, you can disable a button using the following code:

<button type="button" ng-click="pageChange('first')" ng-disabled="first" class="btn btn-link">First</button>

If you simply want to prevent a function from executing in the view:

<a href="" ng-click="!first && pageChange('first')">

Answer №2

If you want to prevent interaction with an element, CSS is the way to go.

.inactive {
   pointer-events: none;
   cursor: default;
}

Utilize ng-class to implement this styling.

Answer №3

It functions perfectly for my needs.

button[disabled="disabled"] {
   pointer-events: none;
   cursor: default;
}

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

Encountering error: Unrecognized provider 'bProvider <- b' when minimizing code with ugl

Encountering an Unknown provider error: bProvider <- b after minifying the code using uglify. This issue arose when I included a new directory 'slidermvHandle' in my common directory.js file. The code runs without any errors before minificatio ...

Using a loop to format the <ol> tag

After creating an HTML script using angular, I was able to successfully display the names in an array as shown below. <div ng-repeat="namep in names"> <li>Name : <span ng-bind="namep.name"></span></li> <li>Age : ...

Is there a method to retrieve all Class elements without using a for-loop?

I am trying to retrieve all elements with a specific class using document.getElementsByClassName(); <body> <div class="circle" id="red"></div> <div class="circle" id="blue"></div> <div class="circle" id="yell ...

Unable to retrieve information from service using Angular 1.6 and TypeScript

I'm having an issue retrieving data from a Service in my Controller. Here is the code for my Service file: import {IHttpService} from 'Angular'; export class MyService { public static $inject = ['$http']; constructor(private $htt ...

retrieve results upon expiry of time limit

What is the best way to retrieve a value after a timeout in the following function? $fetch: function($timeout) { var breadCrumbs; info = []; $timeout(function() { info = getCrumbs(); console.log(info); ...

Having difficulty transferring data from a JSON file on a different domain to a variable using Ajax

As a beginner in Ajax, I am currently exploring the use of Ajax Cross domain functionality to fetch data. The Ajax function is triggered from test.php, which then calls stats.php to request the desired data. The content of Stats.php: <?php $data = ...

Incorporate React into current Node express application by utilizing a content delivery network (CD

I'm currently in the process of developing a web application utilizing both Node and React. Instead of having separate Node and React applications, I decided to integrate React directly into my existing setup. To achieve this, I attempted importing th ...

The computed value failing to refresh

I'm facing an interesting issue. I am currently developing a simple time tracking application. Here is the form I have created: <form class="form" @submit.prevent="saveHours"> <div class="status"> <div class="selector" v-f ...

Can one initiate a server within Zapier Code?

Is there a way to send an HTTP CODE = 200 with a response body of 'OK' when receiving a notification on Zapier? I attempted to use the following code snippet in Zapier: var http = require('http'); const server = http.createServer((r ...

Automatically submitting an HTML form from a JSP page

Encountering the same origin policy issue with Ajax, but in need of sending a form post to a different server. The question at hand is: How can I call my JSP to automatically submit a form to another server? Attempts to use an AJAX call to the JSP page h ...

sending a file using ajax and handling it with php

Curious if there's a way to upload a binary file through ajax and php, without having to refresh the entire page like with a traditional html form. I've been able to gather input from radio buttons and text boxes using forms and javascript, but w ...

Transferring data to a child component through Route parameters

Although I have come across numerous questions and answers related to my query, I still seem unable to implement the solutions correctly. Every time I try, I end up with an 'undefined' error in my props. Let's take a look at my parent compo ...

Tips for defining a function without an arrow as a parameter

Understand that there may be individuals quick to flag this as a duplicate question, but trust me when I say that I have exhaustively searched on Google for almost an hour before turning to ask here. methods: { stylizeHeader: debounce(event => { ...

JavaScript array loading failed for the C# web service

I am encountering an issue with a JavaScript object in my application that contains an array object, which is a collection of objects with two properties (Name, Value) on the server-side. Despite my efforts, when the code reaches the C# web service, the C ...

Why do I keep getting errors in TypeScript when I manipulate DOM elements using getElementsByClassName(), even though my application still functions properly?

I am dealing with an Angular2 application. Unfortunately, I have had to resort to using the following code within a component method (I know it's not ideal, but...): let confirmWindowDOM = document.getElementsByClassName('modal')[0]; confir ...

Storing information in a parse table using NodeJs

I am trying to add data to a Parse table. At the top of my code, I have the line import Parse from 'parse/node';. Here is how I am inserting the data: const game = Parse.Object.extend('Game'); const query = new Parse.Query(game); que ...

Global variables become undefined after utilizing jQuery's getScript() method for assignment

I have a few global variables named var1, var2, and so on... Instead of immediately initializing these variables, I wait until later to instantiate them using jQuery from a constructor located in a separate javascript file. However, after this instantiat ...

AngularJs $resource HTTP status monitoring

As a newcomer to AngularJs, I am delving into the complexities of utilizing $resource to retrieve the HTTP status code that was returned. I have set up a factory and attempted one method to obtain the HTTP header but haven't had any success so far. a ...

I'm having trouble grasping the sequence of events in this async example

Currently, I'm delving into the world of JavaScript and Node.js, but I find myself facing challenges with asynchronous execution. I have a piece of code that may not be following best practices, but I am eager to understand why the file remains open w ...

Node, Express, and Angular redirection problem encountered

I have a web application built with node, express, and angular. The app consists of two main pages - a user profile page and a login page. My goal is to redirect any user who is not logged in to the login page when they try to access the profile page. Howe ...