javascript - AngularJS - ng-if on a large amount of values -


hello guys,

i div display if unknown (that can large) amount of conditions met. :

<div ng-if="foreach(arrayofvalues row) row.username != ''"> nice data</div> 

so whenever data correctly populated , of has been received (it's multiple sources) bloc of data appears @ once.

thanks ahead !

just in controller:

.controller('mycontroller', function($scope){     $scope.isvalid = function(){       for(var = 0; < $scope.arrayofvalues.length; i++){           if($scope.arrayofvalues.username == '') return false       }       return true;    })    }) 

html inside controller on page:

<div ng-if="isvalid()"> nice data</div> 

note calling function isn't efficient, has execute isvalid every digest cycle. it'd better $watch data , set validity flag on scope.

edit:

even better, since check if data has loaded, use $q.all data requests set loaded flag on scope.

edit2- watch solution:

.controller('mycontroller', function($scope){    $scope.loaded = false;     var clearwatch = $scope.$watch('arrayofvalues', function(){       $scope.loaded = true       for(var = 0; < $scope.arrayofvalues.length; i++){           if($scope.arrayofvalues.username == ''){               $scope.loaded = false;               break;           }       }       if($scope.loaded){          clearwatch();       }    }, true)  }) 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -