Angular JS use NG-Hide with function

6k views Asked by At

I try to create an Angular JS function that is displaying or hiding a Div in case that a certain requirement is met. I do have the problem now that the function is not properly called and both divs are either visible or not visible (In the test case div 1 should be shown and div 2 not).

testApp.controller('MyController', ['$scope','$http',
function ($scope,$http) {
    $scope.checkValue = function(value){
    if(value >= 1)
        return true;
    else
        return false;
    };
}]);

In the html file I try to hide the Divs using the following parameters

<div class="classa" ng-hide="requestsExisting({{profile.arrayA.length}})">
<div class="classb" ng-hide="requestsExisting({{profile.arrayB.length}})">

Is during the run time the {{profile.parameterA.length}}passed to the function or the actual value that is stored in this variables? (It's 1 for arrayA and 0 for ArrayB)

2

There are 2 answers

0
No Idea For Name On BEST ANSWER

you don't need the "{{" sign. just do

<div class="classa" ng-hide="requestsExisting(profile.arrayA.length)">
<div class="classb" ng-hide="requestsExisting(profile.arrayB.length)">

the double curly brace is to put the value of the object in the html

The double curly brace notation {{ }} to bind expressions to elements is built-in Angular markup

0
Eylen On

I think that it should work just with this code

<div class="classa" ng-hide="requestsExisting(profile.arrayA.length)">
<div class="classb" ng-hide="requestsExisting(profile.arrayB.length)">

I think that you don't need to use {{}} inside the ng-hide directive