Disable password styling in Angular by changing the type attribute to "none."

I'm curious about something, I want to add a checkbox in my application that can toggle the visibility of the password input field.

HTML

<input type="text" ng-model="data.username" placeholder="username" value="username" class="form-control" popover="inserisci qui il tuo username" popover-trigger="focus" popover-placement="right"/><br>
<input id="pwd" type="password" ng-model="data.password" placeholder="password" value="password" class="form-control" popover="inserisci qua la tua password" popover-trigger="focus" popover-placement="right"/><br>
<input class="btn-primary btn-lg" type="submit" value="Login">
<button class="btn-warning btn-lg" type="button" ng-click="cancel()">CANCELLA</button>
<input ng-model="show" type="checkbox"><span>Show Password</span>

I am looking to implement a function on the show checkbox that changes the style or type of the password field. I've come across discussions where people mention that changing the type is not possible, so I'm considering changing the field's style as an option. Is there a way to change the style of a password field to 'none'?
EDIT
Although I tried Alex's solution and it worked, I attempted to bind the type in this manner

HTML

<input id="pwd" type="{{passwordtype}}" ng-model="data.password" placeholder="password" value="password" class="form-control" popover="inserisci qua la tua password" popover-trigger="focus" popover-placement="right"/><br>
<input ng-model='check' ng-change="show()" type="checkbox"><span>SHOW PASSWORD</span>

JS

$scope.check=false
$scope.show=function(){
    if($scope.check==false){
        $scope.check=true;
        $scope.passwordtype='text'
    }else{
        $scope.check=false;
        $scope.passwordtype='password'
    }
}

It works on Internet Explorer and Firefox, but interestingly on Chrome and Opera, when I expect text, the field changes from a disc to a square. Any idea why?

Answer №1

If you want to show and hide elements on a webpage, you can employ a simple magic trick.

For example:

<input ng-show="show" type="text" ng-model="password">
<input ng-hide="show" type="password" ng-model="password">
<input type="checkbox" ng-model="show" ng-checked="false">

Check out this live demonstration: http://jsfiddle.net/choroshin/694f7/1/

Answer №2

Dynamic execution is not feasible in Internet Explorer due to compatibility issues. However, if you insist on achieving this functionality, consider utilizing the Show/Hide feature provided by AngularJS. Display one element when the checkbox is checked and show the other when it is not.

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

Customize global styles in React using the `react-helmet` library with a `:root`

Is it possible to enhance global styles in React by adding a :root style block with CSS variables? I included the following code snippet in my layout.tsx file, but when I run it in Visual Studio 2022 React project, the page appears blank. However, if I rep ...

Scraping the web with Python: Selenium HTML elements may differ from what is shown in the inspect tool

In my current academic project, I am facing an issue with scraping news articles from websites. The problem arises when parsing HTML code in Python because the code obtained from the page source is different from what is shown in the Inspect Element tool. ...

What is the best way to utilize ng-if to conceal a component in AngularJS when a button in a separate component is clicked?

I am facing a challenge with two child components within a parent component. My goal is to hide component1 when a button in component2 is clicked. Below is an illustration of the current code I am handling: Parent Component HTML: <div ng-app='ap ...

Keep the Bootstrap dropdown menu open when the search bar is in focus

I am working on a customized bootstrap dropdown menu that needs to remain open when the search bar within the Events dropdown is focused. I have managed to make it open and close on hover, but now I need it to stay open under certain conditions. Below is ...

Querying the database to check for the presence of a file in a .js file on Google App Engine

I'm currently working on implementing an upload button for users to upload files to our storage system using Google App Engine with Python, as well as HTML and JavaScript for the views. To achieve this, we have an HTML file and a.js script that promp ...

Navigating with Angular and NodeJS

I have chosen Node.js for the backend and Angular for the frontend in my project. However, I am curious about what would happen if I were to declare the same route for both the front end and back end. Although I have not tested this scenario yet. For exam ...

What could be causing the mousewheel event in my code to remain active?

Whenever I try to scroll on Google Chrome, an error occurs on my website. jquery-3.3.1.min.js:2 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See To resolve this issue: $(document).ready(f ...

Unable to establish communication with server. Facing issues in connecting AngularJS with NodeJS

I am currently working on establishing a communication process between my server and client to receive either a "success" or "failure" response. The server is being developed using node.js with the express framework, while the client is built using angular ...

How can I line up elements in different divs when the width is adjusting based on the window size?

Trying to align a search input and a result element in separate containers when the window size changes. Looking for a solution without using Javascript. One window size: https://i.sstatic.net/LiQtY.png A smaller window: https://i.sstatic.net/dgj4I.png C ...

<a> slightly off-centered horizontal alignment

I've been trying to center a link using different methods like text-align:center and display:inline-block, but it seems to be slightly off-center. I've attached images along with my code below for reference. Any assistance would be greatly apprec ...

The script section within the Angular controller function was not executed, and as a result, the values were not properly

When I click on the navigation links in my application, I want to load an external HTML file. (See [index.html]) <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" ng-app="defaultApp"> <head> </head> <body ng-controller= ...

Lazy loading images using the lazysizes plugin allows the browser to calculate the total page size without waiting for the images to

Having trouble with the lazysizes plugin and srcset on a fluid layout. The page keeps extending as you scroll instead of loading to the correct length You can see my attempt using the bootstrap framework in this CodePen demo After much research, it seems ...

Devextreme experiences the submission of multiple forms simultaneously

While working with Devextreme forms in Angular 2, I encountered an issue with two separate forms. Whenever I click the submit button on either the first or second form, both forms undergo validation. Why is this happening? https://i.sstatic.net/1orrY.png ...

Issues with boxes showing or concealing depending on the chosen option

I am encountering an issue with a dynamic dropdown feature. The secondary box is supposed to appear based on the selection of the first box. However, as soon as I select an option in the second box, it disappears immediately. I suspect the problem lies wit ...

Custom-designed scroll bars that perfectly match the size of the content window

Currently attempting to adjust the layout of my webpages in order to enable scrolling for dynamic content across various pages. I have made adjustments to the header, footer, and sidebar elements, but am facing issues with implementing proper overflow prop ...

Error: The object being referenced (scope.awesomeThings) is undefined and unable to be evaluated

Each time I run the grunt test command, I encounter this error. I set up a project using yo angular and attempted to execute the example code provided in Yeoman's scaffold. Something seems to have gone awry here - below is the code snippet that I trie ...

Utilizing getElementsByClassName for web scraping: encountering inaccurate outcomes

I am attempting to extract the inner text from all classes with the className = "disabled" within the provided snippet of HTML Code: HTML code In my effort to achieve this task using MS Access (VBA), the code I have implemented is as follows: Set IE = C ...

What are the steps for transitioning from an HTML-table layout solution to a floating-div solution?

Whenever I need to display a list of items with differently sized images on the left and corresponding text on the right, I always face this challenge: Click here for image link For many years, my go-to solution has been using HTML tables like this: < ...

Using CSS and Jquery to apply a CSS class to a popup window

I've been attempting to assign the CSS class .dialogStyle to a dialog box, but for some reason, it doesn't seem to be taking effect. <!doctype html> <head> <meta charset="utf-8" /> <title>Test</title> <link r ...

Why does ng-pattern run even when the input field is disabled?

Why does angular evaluate a pattern when the input field is disabled? Shouldn't it behave the same way as it does when the input field is hidden? For a demonstration, please refer to this fiddle: Fiddle for reference <div ng-app> <div n ...