1

I have implemented two div where i have used some drop down control in a div named as div1 .I want to hide div2 until the any value is selected in drop down.I want to know how to hide or show a div on ng-change or untill any value is selected div2 must not be shown. 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 untill and unless a value is selected by my dropdown div2 will be hidden.

Shian JA
  • 848
  • 4
  • 15
  • 52

1 Answers1

2

First assign a variable to your Choice List. For example

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

Then simply use ng-show (doc)

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

The above is also equivalent to:

<div id="div2" ng-show="homeCountry != null">
SDekov
  • 9,276
  • 1
  • 20
  • 50
  • hmecountry is my div id or what? as i have to hide th complete div2 – Shian JA Jul 13 '15 at 08:06
  • `ng-model="homeCountry"` will simply create a variable called `homeCountry` and bind it to the value of the SELECT. Read [this](https://docs.angularjs.org/api/ng/directive/ngModel) for more info. – SDekov Jul 13 '15 at 08:07