Shashishekhar Hasabnis
Shashishekhar Hasabnis

Reputation: 1756

ng-show not working properly atfer ng-init

Here is my code

<div ng-init="$scope.bot_assistance='false'">
    <label for="switch">Bot Assistance:
        <input type="checkbox" id="switch" ng-model="$scope.bot_assistance">
    </label><br/>
    <p>Value:-{{ $scope.bot_assistance }}</p>
    <div ng-hide="$scope.bot_assistance">Bot Assist Disabled</div>
</div>

After my page loads I can see the value of $scope.bot_assistance='false' but why is my ng-hide evaluating to be true and not showing up on the page. Also it shows up div block after I check and uncheck again. So I guess it sets ng-hide=true after checking the checkbox and shows up after again clicking the checkbox making <div ng-hide="$scope.bot_assistance"> to be false which is what I want it to work but After page load it doesn't show the ng-hide block. Why is it so can anyone help me out. Thanks in advance.

Upvotes: 0

Views: 785

Answers (1)

Stanislav Kvitash
Stanislav Kvitash

Reputation: 4622

  1. Do not use $scope inside the template (are you really using $scope.$scope inside your controller?)
  2. Do not initialize the initial value with ngInit
  3. Do not initialize boolean variable with a string value bot_assistance='false'

Upvotes: 2

Related Questions