Derooie
Derooie

Reputation: 121

How can i use a angular variable coming from controller in html?

i have a question on how to get variables set in my controller in a html tag?

Example:

<table class="table table-striped table-bordered table-hover" ng-hide="checked">

The ng-hide should be a variable. In my controller i have:

$scope.checked = "checked";

How to use the variable in the above example?

<table class="table table-striped table-bordered table-hover" ng-hide="{{ checked }}">

Doesnt work.

Upvotes: 0

Views: 80

Answers (2)

Milad
Milad

Reputation: 28592

ng-hide ng-show ng-desabled all of them rely on a true/false variable,

So you have to consider a $scope.checked=false or true in your controller , and that will work

Upvotes: 1

ugursogukpinar
ugursogukpinar

Reputation: 337

I can give you this.

 <!DOCTYPE html>
    <html ng-app>
    <head>
        <title></title>
        <script type="text/javascript" src="angular.min.js"></script>
        <script type="text/javascript">
        function testCtrl ($scope) {
            $scope.checked = true;

            $scope.changeHide = function(){
                $scope.checked = false;
            }
        }
        </script>
    </head>
    <body ng-controller="testCtrl">
        <div ng-show="checked">
            Must be shown on start.
        </div>
        <button ng-click="changeHide()">Hide</button>
    </body>
    </html>

ng-show or ng-hide , it does not matter.

Upvotes: 0

Related Questions