Tips for displaying or concealing a div using Angular Js

I have set up two div elements with a dropdown control in one named div1. I am looking to hide div2 until a value is selected in the dropdown. How can I show or hide a div based on ng-change, ensuring that div2 remains hidden until a value is selected? Code:-

<div data-ng-app="CustomerNew" data-ng-controller="CreateCustomerCtrl as custom" ng-init="getFormData();">
    <div id="div1">
    <tr>
    <td nowrap>Company Name:
    </td>
    <td>
    <asp:TextBox ID="txtCompanyName" runat="server" CssClass="NormalTextBox" TabIndex="1" Width="160px" Height="10px" ng-model="custom.txtCompanyName" required=""></asp:TextBox>  
    </td>
    </tr>
    <tr>
    <td>Country:</td>
    <td>
    <select id="listHomeCountry1" style="width: 182px !important; height: 34px;">
    <option value="0">--- Select an option ---</option>
    <option data-ng-repeat="Cntry in listHomeCountry" ng-model="custom.listHomeCountry" ng-change="" value="{{Cntry._key}}">{{Cntry._value}}</option>
    </select>
    </tr> 


    <div id="div2">
     <table style="position: relative; left: 0px;">
    <tr align="left">
    <td nowrap style="width: 200px">
    <asp:Label ID="lblContactAddress1" runat="server" CssClass="NormalTextBox" Width="60%"></asp:Label></td>
    <td nowrap>
    <asp:TextBox ID="txtContactAddress1" TabIndex="3" Name="txtContactAddress1" runat="server" CssClass="NormalTextBox" Columns="35" Width="160px" Height="10px" ng-model="custom.txtContactAddress1" required=""></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="lblContactAddress2" runat="server" CssClass="NormalTextBox"></asp:Label></td>
    <td>
    <asp:TextBox ID="txtContactAddress2" Name="txtContactAddress2" TabIndex="4" runat="server" CssClass="NormalTextBox" Columns="35" Width="160px" Height="10px" ng-model="custom.txtContactAddress2" required=""></asp:TextBox>
    </td>
    </tr>
    </div>
    </div>

Now I want div2 to remain hidden until a value is selected in my dropdown.

Answer №1

To start, set a variable for your Choice List. For instance

<select id="listHomeCountry1" ng-model="homeCounrty">

After that, just utilize ng-show (reference)

<div id="div2" ng-show="homeCountry">

This is similar to:

<div id="div2" ng-show="homeCountry != null">

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

Leveraging Multiple @Input Decorators in Ionic 3 and Angular 2

Within my Ionic 3 project, I have developed a custom component called my-component. Utilizing the angular @Input functionality, data can be passed to this component with ease. In this case, I have two inputs defined as: @Input('finder') myFinder ...

What is the proper way to utilize queries in BlitzJS?

I am attempting to extract data from a table by filtering based on the relationship with the Blitzjs framework. However, I am facing difficulties using queries as it seems to be the only option available. Every time I try to call the quer ...

One clever AngularJS hack

Can anyone help me figure out how to call a function in a controller specifically for the first 'li' element in a 'ul' that is using ng-repeat? For example, I have a function in my controller: var init = function () { var a = this; ...

`The Importance of Validating Enum Arrays in Typescript Using Class-Validator`

Is there a way to validate an array of enums in a DTO without getting misleading error messages? Here is an example of my DTO: import { IsArray, IsEmail, IsEnum, IsIn, IsNotEmpty, IsString } from "class-validator"; import { UserAction, UserModul ...

Typescript error: Cannot access property "status" on type "never".ts(2339)

Currently, I have a method that utilizes nextjs/auth to sign in with credentials from a form. However, I am encountering a type checking error Object is possibly 'undefined'.ts(2532) const doStuff = async (values: any) => { const result: S ...

Angular Bootstrap Datepicker provides us with a date object, but I need it in the Date format

My desired date format is "Wed Aug 07 2019 16:42:07 GMT+0530 (India Standard Time)", but instead I am receiving { year: 1789, month: 7, day: 14 } from ngbDatepicker. Any assistance on resolving this issue would be greatly appreciated. ...

Setting up default values for AngularJs and JqueryUI slider

Just making my debut post here, hoping it covers everything. I'm working with AngularJs and I've incorporated a JqueryUI slider using an angular directive. I've come across numerous examples on how to do this, but none of them explain how t ...

Experiment with AngularJS and Jasmine by utilizing the stand-alone command line interface for testing

I have been working on a basic .js file and testing it with Jasmine. The tests run smoothly when using Jasmine's SpecRunner.html. However, I was wondering if it is possible to achieve the same results through a command line interface. I do have node ...

The reason for ng-bind not functioning properly with ng-app is due to a compatibility

I've recently started learning angularjs and encountered an issue with ng-bind not working when used with ng-app. However, I found that leaving ng-app empty as ng-app="", actually made it work. Can someone shed some light on this? <!doctype html ...

Navigating through diverse objects in Typescript

My challenge involves a state object and an update object that will merge with the state object. However, if the update value is null, it should be deleted instead of just combining them using {...a, ...b}. const obj = { other: new Date(), num: 5, ...

What is the reason for instances being compatible even if their class constructors do not match?

Why are the constructors in the example below not compatible, but their instances are? class Individual { name: string; age: number; constructor(name: string, age: number) { this.name = name; this.age = age; } } class Worker { name: st ...

Utilizing TypeORM to selectively choose data in OneToMany relationships

I am looking to create a TypeORM query that pulls data from the database. Specifically, I want to retrieve all clients who have made a purchase but have not initiated a return. Here is the structure of the database: Clients: Id (Int, primary column) Purc ...

"Implement AngularJS to dynamically show additional items upon clicking on the 'show more'

I want to create a list of items that can be expanded by clicking on a "more" link to display an additional 10 items. Here is the code I have been working with: <div ng-repeat="item in itemList()"> {{item.name}} </div> This is my current cont ...

Issue with ng-click not triggering the $mdDialog callback

Utilizing Angular Material, I have functionality in TasksCtrl that triggers a $mdDialog - utilizing the locals property to pass an object that will be changed in DialogCtrl before being returned to the view. Nevertheless, the .then() callbacks do not trig ...

Creating test cases for a service that relies on a Repository<Entity> to consume another service

Having trouble creating tests for an auth.service that seems pretty straightforward from the title. However, every time I run the tests, I encounter this error: TypeError: Converting circular structure to JSON --> starting at object with cons ...

Deciphering the AngularJS Component Hierarchy and Managing Identifiers for Freshly Generated Objects (using HTTP)

In my project using Angular 1, I have developed a todo list application which consists of two components. The first is a smart (container) component responsible for server-side interactions, while the second is a dumb/pure/stateless presentation component ...

Tips for handling race conditions in webdriver

My app uses a combination of angular and asp.net, but I'm facing an issue with the home page redirection. Initially, all routing was handled by the angular app itself, but due to certain requirements, we had to change it so that the home page redirect ...

Developing a dynamic object in Typescript to structure and optimize API responses

Currently Working Explanation: This is similar to the data array received from the API response responseBarDataStacked = [ { sku: "Data 1", month: "Jun", value: 20 }, { sku: "Data 2", month: "Jun", value: 25 ...

Remove an item from an array in JavaScript by specifying its value, with compatibility for IE8

Is there a way to remove an item from an array by its value rather than index, while ensuring compatibility with IE8? Any assistance would be greatly appreciated. Thank you. Below is the array in question: var myArray = ['one', 'two', ...

Embracing the "export ... from" feature in the TypeScript compiler

Can the tsc compiler handle this particular export statement? export {PromiseWrapper, Promise, PromiseCompleter} from 'angular2/src/facade/promise'; Your assistance is greatly appreciated! ...