The ng-disable function is not displaying correctly

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.firstName = false;
    $scope.toggle = function(){
        $scope.firstName = !$scope.firstName;
    };
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <body>
    <div ng-app="myApp" ng-controller="myCtrl">
      <button ng-click=toggle()>ToGgLe</button>
      <input type="text" ng-disabled="{{firstName}}">
   </div>
  </body>
</html>

Trying to implement a toggle function for an input field using AngularJS. While the value changes in the DOM, the input field is not rendering properly. Seeking assistance to resolve the issue. Thank you.

Answer №1

No need for string interpolation here, because ngDisabled can accept the expression directly with firstName.

<input type="text" ng-disabled="firstName">

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.firstName =false;
    $scope.toggle = function(){
        $scope.firstName =!$scope.firstName ;
    };
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <body>
    <div ng-app="myApp" ng-controller="myCtrl">
      <button ng-click=toggle()>ToGgLe</button>
      <input type="text" ng-disabled="firstName">
   </div>
  </body>
</html>

Answer №2

You are not required to utilize the interpolation operator {{}}

let app = angular.module('myApp', []);;
app.controller('myCtrl', function($scope) {
 $scope.firstName =false;
    $scope.toggle = function(){
        $scope.firstName =!$scope.firstName ;
    };
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <body>
    <div ng-app="myApp" ng-controller="myCtrl">
      <button ng-click=toggle()>ToGgLe</button>
      <input type="text" ng-disabled="firstName">
   </div>
  </body>
</html>

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

Obtaining various values for checkboxes using dynamic data in a React application

Retrieve all checkbox values dynamically import * as React from "react"; import Checkbox from "@mui/material/Checkbox"; import FormControlLabel from "@mui/material/FormControlLabel"; import axios from "axios"; expor ...

What are the methods to ascertain whether an HTML element possesses a pseudo element?

Is there a method to identify whether an HTML element has a pseudo element (::before / ::after) applied to it without invoking the function: window.getComputedStyle(element, ":before/:after"); MODIFIED: the response is NEGATIVE The issue with getCompute ...

Error: OpenAI's transcription API has encountered a bad request issue

const FormData = require('form-data'); const data = new FormData(); console.log('buffer: ', buffer); console.log('typeof buffer: ', typeof buffer); const filename = new Date().getTime().toString() + '.w ...

AngularJS version 1.0.7 has a mysterious absence of the locationProvider

I am currently working on an AngularJS 1.0.7 web application. In my app.js file, I'm attempting to implement $locationProvider for htm5Mode functionality. However, upon running the code, I encounter an error stating that $locationProvider is undefine ...

Dealing with the problem of delayed image loading in AngularJS due to a setTimeout conflict

The issue: Upon page load, some images are still processing and not displaying (even though the image URLs are known). The resolution: To address this problem, a customized directive was developed to showcase a loading spinner as a placeholder until the i ...

What is the best way to conceal a parent element with jquery?

Let's say we have the following HTML structure: <li class="fooli"> <a class="foo" href="javascript:foo(this);">anchor</a> </li> <li class="fooli"> <a class="foo" href="javascript:foo(this);">anchor</a> ...

Having trouble with the npm Twitter API functionality?

I'm attempting to execute a simple stream using an example code snippet. Here is the code I am working with: var twit = require('twitter'); var twitter = new twit({ consumer_key: '[KEY]', consumer_secret: &ap ...

Tips for incorporating a Font Awesome icon <i> within a select dropdown and customizing its appearance

I am facing an issue while trying to insert an icon into a select option. The error message I received is: Warning: validateDOMNesting(...): cannot appear as a child of <option> To indicate that certain fields are required, I am using asterisk ic ...

modifying the identification value in HTML and then reverting it

Although this may seem like messy code, I'm really in need of assistance with a problem that has stumped me. Currently, I am working on an E-shop project where I have modals for displaying products. Within these modals, there is a button that allows u ...

Exploring the world of web programming

Looking for top-notch resources to learn about JavaScript, AJAX, CodeIgniter and Smarty. Any recommendations? ...

Anticipating the completion of a process.nextTick cycle

Problem Statement I am currently working on a Node.js application that involves complex calculations and utilizes recursive algorithms. The code snippet below gives a brief overview of how the calculations are performed: // routes.js - express.js routes ...

The Azure SpeechSynthesizer encountered an error due to using HTTP instead of the expected HTTPS protocol. This issue can be resolved by installing the NPM package `microsoft

Recently, I have been encountering an issue with the microsoft-congnitiveservices-speech-sdk npm package. Everything was working smoothly until randomly an error started popping up. This could be due to a browser update or a minor package update - I'm ...

Illustration of a D3 graph demo

I'm currently working on modifying a d3.js graph example originally created by Mike Bostock. My goal is to replace the d3.csv method with d3.json. I made adjustments to parts of the original code, but unfortunately, my graph has disappeared without an ...

Is there a way to specify the dimensions of the canvas in my image editing software based on the user-input

Here is the code and link for my unique image editor. I would like to allow users to enter the desired width and height of the selection area. For example, if a user enters a width of 300 and height of 200, the selection size will adjust accordingly. Addit ...

place an image next to a div element

Currently, I have a table-like structure with two columns that I am struggling to make mobile responsive. Take a look at the code snippet below: setTimeout(function() { odometer.innerHTML = '1925' }) .fiftyFiftySection { back ...

"Exploring the Possibilities with WordPress and Waypoint Js

After exploring various resources and tutorials online, I am struggling to implement Waypoints with WordPress. Despite placing the necessary files like waypoints.min.js and waypoints.js in the designated download folder within the js directory of my templa ...

Using JavaScript to retrieve data from a JSON file and showcase it on a jQuery mobile webpage

I am struggling to retrieve JSON data from a PHP URL using JavaScript and display it within a JQuery mobile "li" tag as a category list. Despite spending the last 8 hours on it, I can't seem to get it working using the code provided below. Any help wo ...

Node-pty in NWjs application causing DLL malfunction

When attempting to run a terminal emulator / command prompt in NW.js using xterm JS and node-pty, I encountered a DLL Error. The following is the log: Uncaught Error: A DLL Initialization Routine Failed. \\?\C:\Users\volke.a\ ...

Prevent users from clicking by using a CSS class in HTML and JavaScript

,hey there buddy 1° Can you help me figure out how to prevent click behavior using the CSS class? 2° I'm unable to add an ID to the HTML element, so I need to use the Class to achieve this. 3° None of my attempts have been successful so far. El ...

Retrieve / - - - - ms within meanio

I have successfully set up the mean stack using the steps provided: $ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash $ sudo apt-get update $ sudo apt-get install nodejs $ npm install -g gulp $ npm install -g bower $ sudo npm install -g mean- ...