Reputation: 399
So in my "articles" example from the MeanJS boilerplate, I added a comments function. The problem is, is that I have to make a separate call to an API endpoint on the server side to load the comments. I was wondering if it is possible to prevent the HTML that contains the comments from being loaded until after the $http call is finished? Where can I find resources on how to do this? I have tried ng-if, and the element in which the comments reside already has a data-ng-init
.
Upvotes: 1
Views: 965
Reputation: 3201
Try this:
app.controller("commentCtrl",function($scope,$http){
$scope.isCommentLoaded=false;
$http.get('/path/to/your/comment/api').then(function(result){
$scope.comments=result.data;
$scope.isCommentLoaded=true;
});
});
and then in your HTML:
<div id="comments" ng-show="isCommentLoaded">
....Your HTML to show comments....
</div>
Upvotes: 3