Reputation: 467
I am new in AngularJS.
I just need to ask that I am fetching data from the server like that.
$http.get(url+'example.php?get=data').
then(function(response) {
$scope.data = response.data.my_data;
});
Now I am using this data in ng-repeat
like in below.
ng-repeat="articles in data.article" and like that.
Now my question is that suppose my angular variable data.article
is empty. So it will give that sorry there is no article otherwise it will go on ng-repeat
loop. Any help will be appreciated.
Thanks
Upvotes: 0
Views: 563
Reputation: 41407
use ng-if
to validate and show message
<div ng-repeat="articles in data.article">
// what ever your content
</div>
<div ng-if="!data.article && data.article.length == 0">
<span> array is empty </span>
</div>
Upvotes: 1
Reputation: 5988
$scope.isLoaded = false;
$http.get(url+'example.php?get=data').
then(function(response) {
$scope.isLoaded = true;
$scope.data = response.data.my_data;
});
<div data-ng-if="isLoaded && data.article"> Sorry, nothing found</div>
Upvotes: 2