Joe Joe - 3 months ago 8
AngularJS Question

Show and Hide Controller not working, AngularJS

I'm trying to get it so that the #water div will show when the water button is clicked and will not when the energy button is clicked. I am trying to use a controller I have made but so far it has not worked.



<meta charset="utf-8">
<link rel="stylesheet" href="css/wisdom.css">
<link rel="stylesheet" href="css/bootstrap.css">s
<script src=""></script>
<script src="http://jquery-1.12.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src = ""></script>
<script src=""></script>


<body ng-app="WebApp">

<div id="water" ng-include src="'menu.html'"></div>

<section ng-controller="StateController">
<div class="btn-group" role="group" ng-model="show" >
<button type="button" class="btn btn-primary" ng-clicked="StateController.setState(1)">Water</button>
<button type="button" class="btn btn-warning" ng-clicked="StateController.setState(2)">Energy</button>

<div ng-include src="'panels.html'" ng-show="StateController.isSet(1)"> </div>

<script src="app.js"></script>


var app = angular.module('WebApp', []);
app.controller('StateController', function(){
this.state = 1;

this.setState = function(selectedState){
this.state = selectedState;

this.isSet = function(givenState){
return this.state === givenState;


make the below changes


 <div id="water"  ng-show="something" ng-include src="'menu.html'"></div>
<button type="button" class="btn btn-primary" ng-click="setState(1)">Water</button>
            <button type="button" class="btn btn-warning" ng-click="setState(2)">Energy</button>


var app = angular.module('WebApp', []);
app.controller('StateController', function($scope){

if you want to show the water div iniatilly then add this before the setstate function in controller


if u dont want then make it as false