Turn off input disable, turn on input enable with AngularJS

Currently, I'm working with AngularJS and trying to implement a switch functionality. My goal is to have the md-input-container disabled by default when the switch is turned off, and enabled again when the switch is turned on.

While my current setup partially works, I am facing an issue where the md-input-container remains enabled even after turning the switch off again.

Below is the HTML code snippet:

<div class="col-md-2">
  <md-switch ng-click="toggleEnabled()">
      Online Sales
  </md-switch>
</div>

<div class="col-md-2">
    <md-input-container class="md-block">
       <label style="color: #e94e18;">Delivery Costs (€)</label>
       <input ng-model="deliveryCosts" ng-disabled="isDisabled">
    </md-input-container>
</div>

Javascript:

//disable md-input-container by default
$scope.isDisabled = true;

$scope.toggleEnabled = (function(){
    $scope.isDisabled = !$scope.isDisabled;
});

Answer №1

$scope.enabled = (function(){
    $scope.disabled = !$scope.disabled;
});

It's possible to access this function directly from the scope variable

<md-switch ng-click="disabled = !disabled">
  Online Sales
</md-switch>

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

Utilizing v-model alongside various JavaScript plugins within a single select element

I've incorporated the jQuery plugins select2 and datepicker into my project, utilizing custom directives for them. Everything was functioning smoothly until I attempted to retrieve the selected value using v-model, which resulted in a failure to bind ...

Troubleshooting: AngularJS encountering difficulty retrieving data from Service

I am encountering an issue with sending data to a controller from a service that calls an API. To demonstrate this problem, I have utilized http://embed.plnkr.co/jEQMch/ as the basis of my sample application and tweaked it to develop a bullet chart. The s ...

AngularJS: Unwrapping the 302 Response

Incorporating AngularJS, I am working on creating a Login page for authenticating against an LDAP server with Spring Security handling the backend authentication. The process involves sending username and password via a post request to the server, which is ...

Testing an npm module that relies on DOM elements can be done by simulating the browser

As a newcomer to developing npm modules, I am currently working on creating my first one. My goal is to have it easily included in the browser using a script tag, accessible via npm install command, and testable by opening an HTML page with the code includ ...

Anychart remains static when the window is resized

After transitioning my AngularJS application to be built with Webpack, I encountered an issue where all the charts utilizing anychart did not resize when the window was resized. This functionality worked perfectly before I migrated to Webpack from using th ...

What is the best way to implement multiple store filters in VueJS?

Just dipping my toes into the world of VueJS with my very first major project. I've incorporated 2 filters in this project for my elements - one is a search bar and the other involves checkboxes. Taking a look at my code, you'll notice a computed ...

Prevent popup content from refreshing: Tips for creating a dynamic user experience

Currently, I am working on a website that is similar to Facebook. One of the features I am implementing is the ability for users to like posts or photos and see who has liked them. However, I am facing an issue with the popup that shows the list of people ...

When using Javascript, the click function is returned as not being a valid function

I am working on a project with two PHP files - index.php and loadimages.php. The index.php page contains a thumbnail gallery and a canvas. The images in the thumbnail gallery are populated by loadimages.php. Here is a snippet of the code from loadimages.ph ...

Convert HTML to JSON using a selection

After selecting multiple values in the alpaca form using a select ui element, I encounter an issue when saving the form. When I use JSON.stringify(val) to generate the JSON data, it only includes the ids of the selected elements. However, I would like the ...

Construction of jQuery Events

I have experience working with jquery tools and recently started exploring the twitter bootstrap src. One interesting thing I've observed is the utilization of the $.Event constructor for event triggering. For example, in cases like the bootstrap mo ...

Method for setting a checkbox as checked based on whether its value can be found in an array

I currently have the following input fields: <div id="my"> <input type="checkbox" value="1" name="names[]"> <input type="checkbox" value="2" name="names[]"> <input type="checkbox" value="3" name="names[]"> <input t ...

Having issues installing Parcel through npm - Encountered an error while parsing package.json information

After creating a package.json file using the command npm init in my project folder, I proceeded to run npm i parcel --save-dev which resulted in an error message: C:\Users\XPRESS\Desktop\starter>npm i parcel --save-dev npm ERR! code ...

The GTLF Loader within react-three/fiber is experiencing issues with loading textures

I am currently using react-thee/fiber 7.0.0 and I have a GLTF file that includes a bin file. Strangely, when viewing my model on gltf-viewer.donmccurdy.com, all the metallic materials and transparent glass show up perfectly. However, when I try to add it t ...

The error message [ERR_HTTP_HEADERS_SENT] is indicating that headers cannot be modified after they have already been sent to the client in a node.js and express

Attempting to retrieve data by Id from records stored in a MSSQL database. For example, trying to make a GET request in Postman like this: localhost:3200/api/v1/players. Encountering an error message: node:_http_outgoing:576 throw new ERR_HTTP_HEADERS_ ...

How to show or hide a textbox in JavaScript?

Within my user control, there is a panel with two controls: ddlType, a drop-down list, and txtOthers, a text box. Initially, txtOthers is set to be invisible. The goal is for txtOthers to become visible when the user selects an option in ddlType that corr ...

The bidirectional data binding is malfunctioning for a Directive using ControllerAs syntax

My directive using ControllerAs syntax was experiencing issues with 2 way binding, Here is an example of the code: restrict: "E", scope: { items: "=" }, controller: "itemsController", controllerAs: "vm", templateUrl: "items.html", replace: true ...

What is the best way to export multiple modules/namespaces with the same name from various files in typescript within index.d.ts?

I am currently in the process of creating a new npm package. I have two TypeScript files, each containing namespaces and modules with the same name 'X'. At the end of each file, I declared the following: export default X; My goal is to import bo ...

Issue with Node REST API: PUT request is failing to update data in the request

Encountering issues while attempting to update data through a PUT request. Despite making the request, the data remains unchanged and continues to display the previous information in Postman. Details of the PUT request sent via Postman: http://localhost: ...

Utilizing an EJS variable within a React render function with webpack - A Guide

I am looking for a way to display personalized information stored in a MySQL database to my users. I am using ejs, webpack, and React for my project. While I found some guidance on how to achieve this without webpack, it doesn't quite fit my needs. Th ...

What is the best way to obtain every occurrence of a certain tag in Node.js?

Currently, I am working on a Node.js script to import a text document that consists of three newspaper articles with several metadata tags. My goal is to extract the contents of two specific tags from each article and store them in an array or JSON file. ...