unable to hide div on loading page. I want to show the div if the value of array is empty.
<div ng-hide="loading" ng-if="users== null || users.length === 0" >
<h3>No Result Found</h3>
</div>
This is what you should do.
//This will check if loading is false and Users are not undefined || less than equal to 0 (empty array)
<div ng-if="!loading || !users || users.length <= 0">
<h3>No Result Found</h3>
</div>
//Show data if users are defined and length is greater than 0
<div ng-if="users && users.length > 0">
<h3>Data</h3>
</div>
Using ng-show and ng-hide
//Show if loading is true or users are undefined or users are empty
//Hide if loading is false or users are defined or users are not empty
<div ng-show="loading || !users || users.length <= 0"
ng-hide="!loading || users || users.length > 0">
<h3>No Result Found</h3>
</div>
//Show if users are defined and length is greater than 0
//Hide if loading is true or users are undefined or users are empty
<div ng-show="users && users.length > 0"
ng-hide="loading || !users || users.length <= 0">
<h3>Data</h3>
</div>
ng-hide/show just sets the display property of the element to "none" whereas, ng-if removes the element from the dom
This may work for you
<div ng-if="!loading && (typeof(users) === 'undefined' || users== null || users.length === 0)" >
<h3>No Result Found</h3>
</div>
This may help you - use && or || as per your case here -
<div ng-hide="loading && users.length == 0">
<h3>No Result Found</h3>
</div>
Boolean([]) === true, so if users is a defined array, the above expression may be truthy even if the array is empty.true, unlike in PHP for example. So the div would be hidden as long as the array is defined, regardless if its empty or not. Simply try it.users.length. Thank You!
ng-hideand check.loading && (users==null || users.length===0)ng-ifremoves DOM,ng-hidesets its display to none. Why bother hiding it, when DOM will be removed?