Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written the code to hide the content initially. whenever I click on the button its displaying that content of data. In similar way I created other button with same behavior as I mentioned.Now the problem is when I click on those buttons one after another, the content of those buttons are displaying on the page.I need to hide one button content when I click on the other button. Can u plz help me to fix this??

What I have tried:

HTML:
Button1:
<button type="button" value="click1"  ng-click="show=!show"><font color="white">Display1</font></button>

<div  ng-show="show">
Helloo hyderabad.
</div>

Button2:
<pre>  <button type="button" value="click1"  ng-click="show1=!show1"><font color="white">Display1</font></button>

<div  ng-show="show1">
Helloo hyderabad.
</div>

JS:
app.controller('MainCtrl', function ($scope) {
    $scope.show = false; // Hide it initially 


});

app.controller('MainCtrl', function ($scope) {
    $scope.show1 = false; // Hide it initially 


});
Posted
Updated 9-Aug-18 1:46am
v2

1 solution

Try this Code. You can create function for the buttons and write the code for hiding the content in it.

<div ng-controller="MainCtrl" ng-app="application">
    
    <button type="button" value="click1" ng-click="ButtonClicked1()"><font color="white">Display1</font></button>

    <button type="button" value="click1" ng-click="ButtonClicked2()"><font color="white">Display1</font></button>

    <div ng-show="show">
        Helloo hyderabad1.
    </div>

    <div ng-show="show1">
        Helloo hyderabad2.
    </div>

</div>

<script>

    var app = angular.module('application', []);
    app.controller('MainCtrl', function ($scope) {
        $scope.show = false; // Hide it initially 

    });

    app.controller('MainCtrl', function ($scope) {


        $scope.show1 = false; // Hide it initially 

        $scope.ButtonClicked1 = function () {
            $scope.show = !$scope.show;
            $scope.show1 = false
        }

        $scope.ButtonClicked2 = function () {
            $scope.show1 = !$scope.show1;
            $scope.show = false
        }

    });


</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900