0

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

2 Answers 2

2
$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>
Sign up to request clarification or add additional context in comments.

Comments

1

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>

2 Comments

It is working data.article.length == 0 but it !data.article doesn't.
if data.article property always exist, then remove it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.