Skip to content Skip to sidebar Skip to footer

Angularjs Run Directive After Success Of $http

I am making a nav using custom directive and when some add/remove anything from that nav I wanted to reflect changes on that nav . If that nav comes from scope then I can update sc

Solution 1:

$http returns a promise and is asynchronous. Your directive runs when your html renders. So what you do is don't render the HTML until you have the response.

HTML:

<divng-if="ready"><divmy-custom-directive></div></div>

Controller:

$scope.ready = false;    
$http.get('/my-request').success(function(){
    $scope.ready = true;
});

This works because the ng-if directive will create the element only if the expression becomes true.

Post a Comment for "Angularjs Run Directive After Success Of $http"