Avatar of ksd123
ksd123
 asked on

Display content based on dropdown selected value in Angular

Hi Experts,

I am newbie to Angular and have a requirement to show the content based on dropdown value in Angular.I have following dropdown  values

None: show no content
Name: Show "Name" content only
Address:Show "Address" content only
All: Show both "Name" and "Address" contents.

I have below code developed in Visual Studio editor which is  working fine (UI screenshots attached ) using Angular,Bootstrap and HTML5.

I need sample working code for my requirement.

<div class="container" >

  <div style="padding:50px;" ng-controller="samplecontroller">

 <div class="row">
     <label class="col-lg-2">
         Status</label>
     <div class="col-lg-5">
         <select class="input-sm">
             
             <option selected value="none">None</option>
             <option value="name">Name</option>
             <option value="address">Address</option>
             <option value="all">All</option>
         </select>
     </div>
 </div>
 </br>
    
  <div class="row">
         <label class="col-lg-2">
             Name</label>
         <div class="col-lg-5">
             <p class="form-group">
                 {{name}}</p>
         </div>

     </div>
 </br>
     
     <div class="row">
                <label class="col-lg-2">
                     Address</label>
                 <div class="col-lg-5">
                    <p class="form-group">
                        {{address}}</p>
                  </div>

       </div>

   </div>

 </div>

Open in new window


<script type="text/javascript">
        function samplecontroller($scope) {
            $scope.name = "FOO";
            $scope.address = "ADDRESS1";
      
        
        }

Open in new window


Thanks in Advance
image1.JPG
image2.JPG
JavaScriptHTML

Avatar of undefined
Last Comment
ksd123

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ksd123

ASKER
Thank you. I need "text" values in dropdown so I have changed below code from s.value to s.text

 <select class="input-sm" ng-model="state" ng-options="s.text for s in status"></select>

Open in new window


In reality, I have 6 dropdown values and 5 divs in a page layout and based on selection  I am displaying divs (none,1,2,3 etc). So the above approach (using ng-hide declaratively on each div)  is the best practice in angular ?

Thanks in Advance
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy