Text is visible when hidden with the <ng-show> directive in Angular Materials

I recently encountered a unique issue while experimenting with Angular Materials for my project. I tried to hide certain elements based on a checkbox selection, and although it worked for most items, the first input box that I attempted to hide ended up displaying as text instead of being hidden.

From what I can tell, this problem seems to be specific to my lack of experience with Angular. As someone who is new to using Angular, I would greatly appreciate any guidance or solutions you may have to offer :)

If you'd like to take a closer look, you can access the Plunkr demo here.

Here is the code snippet:

<html lang="en" >
   <head>
      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
      <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
      <script language="javascript">
          angular
            .module('app', ['ngMaterial'])

      </script>      
   </head>
   <body ng-app="app"> 
      <div id="tabContainer" ng-cloak>
         <md-content class="md-padding">
            <md-tabs class="md-accent" md-dynamic-height >
               <md-tab id="tab1">
                  <md-tab-label>1</md-tab-label>
                  <md-tab-body>
                    <label for="hello">
                      <br/>
                      <md-checkbox id="1" ng-model="checked">
                        Checkbox #1
                      </md-checkbox>
                    </label>
                     <br/>
                     <md-input-container>
                       <label for="2">Input #1</label>
                        <input ng-show="checked">
                     </md-input-container>
                     <br/>
                     <md-input-container>
                       <label for="3">Drop Down</label>
                       <md-select ng-model="selectedUser" ng-show="checked">
                         <md-option>What's up?</md-option>
                         <md-option>Yo?</md-option>
                         <md-option>Why is "Brother" Input there when we hide?</md-option>
                         <md-option>Idk!? He's suppose to be hidden!</md-option>
                       </md-select>
                     </md-input-container>
                     </md-tab-body>
               </md-tab>
               <md-tab id="tab2" >
                  <md-tab-label>2</md-tab-label>
                  <md-tab-body>Item #2 <br/>selectedIndex = 1;</md-tab-body>
               </md-tab>
               <md-tab id="tab3">
                  <md-tab-label>3</md-tab-label>
                  <md-tab-body>Item #3<br/>selected Index = 2;</md-tab-body>
               </md-tab>
            </md-tabs>
         </md-content>
      </div>
   </body>
</html>

Answer №1

To achieve the desired effect, you can add the ng-hide and ng-show directives to the md-input-container element.

Here is a link to a demonstration: http://plnkr.co/edit/1ieqQtCEBrZzoY9SWh16?p=preview

<md-input-container ng-hide="checked">
  <label for="2">Input #1</label>
   <input >
</md-input-container>
<br/>
<md-input-container ng-show="checked">
  <label for="3">Drop Down</label>
  <md-select ng-model="selectedUser">
    <md-option>What's up?</md-option>
    <md-option>Yo?</md-option>
    <md-option>Why is "Brother" Input there when we hide?</md-option>
    <md-option>Idk!? He's suppose to be hidden!</md-option>
  </md-select>
</md-input-container>

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

Why won't my express app pass this variable to jade?

My express application includes the following code snippet: app.get('/dashboard', function (req, res) { Student.findOne({ email: req.session.email }).exec(function (err, studentData) { if (studentData) { conso ...

Unable to render nested HTML tag in simple React.JS component

I'm currently working on setting up my first component. After following a tutorial, I tried implementing their code to create the component. The code does inject the first <div> into the HTML document, but the <h1> element is missing. In ...

What steps should I take to successfully install using npm if I keep encountering the same error?

Every time I attempt to install a package using npm, I encounter the following warning: npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b3aeaba2b3be ...

The Express server is set up with CORS enabled, however, it continues to encounter issues when attempting to make asynchronous HTTP requests from

We're currently experiencing an unusual issue and are seeking assistance to resolve it. Initially, our Express server is functioning well as an API when accessed from the same domain. However, we also need to utilize this API on our computers for tes ...

What is the best way to pass only the second parameter to a function in TypeScript?

Let's consider a TypeScript function as shown below: openMultipleAddFormModal(commission?: Commission, people?: People): void { // some data } To make a parameter optional, I have added the Optional Chaining operator. Now, how can I modify the code ...

javascriptretrieve the second class from the element

HTML Code : <span class="button" onclick="javascript:buttonClicked();">Log In</span> <div class="modal-bg" style="display: none;"> <div class="modal"> <span>Log In<a href="#close" class="close">&# ...

When using Jest, it is not possible to match 'undefined' using 'expect.any(Object)' or 'expect.anything()'

Looking to test the following module. import * as apiUtils from './apiUtils'; export function awardPoints(pointsAwarding) { return apiUtils.callApiService("POST", "points", pointsAwarding); } This is the test in question. it("should call ap ...

Issues with invoking JavaScript functions

In my HTML page, I'm calling a function from a separate .js file named jQuery.loadjson.js. The syntax being used is $('#data').loadJSON(data); #data refers to a div element, and data is a JSON object. However, when I try to debug this in Fi ...

The File Reader just informed me that parameter 1 is not in the form of a blob

When working with a file input in my React component, I keep encountering an error with the FileReader. Here's the specific error message: Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not o ...

What is the best method to retrieve the correct object from a dynamic array based on the name and value of a text field?

I'm having trouble dynamically changing the values in an array as I type and submit textfields. I've tried linking the exercise key to the necessary values, but it's not working. Below is the main function: export default class AddWorkoutF ...

Angular-js: Handling HTTP status code for aborted requests

When terminating an http request like this: $scope.stopRequest = function() { if (terminator) terminator.resolve(); terminator = $q.defer(); $http({ method: 'GET', url: 'http://www.google.com/', time ...

Tips for effectively transferring information across nested ng-containers and ng-templates

I am in the process of developing a datatable module with a specific implementation in mind. My goal is to be able to import the module and utilize its components as shown below: randomcomponent.component.html <datatable [data]="tableData"> ...

Creating a diverse layout by dynamically adding divs without achieving uniformity in the grid

I'm working on dynamically generating a grid of divs with a specific size using the code below: function createGrid(gridSize) { var container = document.getElementById('container'); for (var i = 0; i < gridSize; i++) { va ...

execute the function once the filereader has completed reading the files

submitTCtoDB(updateTagForm:any){ for(let i=0;i<this.selectedFileList.length;i++){ let file=this.selectedFileList[i]; this.readFile(file, function(selectedFileList) { this.submitTC(updateTagForm,selectedFileList); }); } } } ...

What is the process for syncing ng-model with external data sources?

Here is a question that I have pondered: Let's consider the HTML code snippet below: <div id="container" ng-controller="Controller"> <my-tag ng-model="values"></my-tag> </div> Now, take a look at the controller defined a ...

Interact with SOAP web service using an Angular application

I have experience consuming Restful services in my Angular applications, but recently a client provided me with a different type of web service at this URL: http://123.618.196.10/WCFTicket/Service1.svc?wsdl. Can I integrate this into an Angular app? I am ...

Ways to identify if one object is positioned above another

So, here's the scenario: I'm trying to figure out how to detect when one element is positioned on top of another. Specifically, I'm dealing with SVG elements: <circle r="210.56" fill="#1ABCDB" id="01" priority="4" cx="658" cy="386">& ...

Error: The prop type validation failed because a `value` prop was provided to a form field in React-Bootstrap-Typehead component

I am currently using the bootstrap-typehead package from https://github.com/ericgio/react-bootstrap-typeahead and struggling to understand why it's causing issues. Could someone help me identify what's wrong with this code that's triggering ...

Retrieve: proper authentication credentials were not provided

Whenever I make a request, everything works fine and I receive the data: const get_players = async()=>{ const response = await fetch('http://127.0.0.1:8000/player_stats/api/players/') const data = await response.json() console. ...

Struggling with passing parameters through a route and displaying them in the Reddit app using React?

I'm currently working on a project that involves displaying threads from various subreddits when a user clicks on a list item using routes and react. However, I've encountered some issues with getting the information to display correctly. Below i ...