1
app.controller("MainController", function($scope, $http){
    $scope.items= [];
    console.log('hi');
    $http.get('../assets/data/data.json').then(function(response) {
        $scope.drinks =response.data.drinks;
    });
});

app.directive('cycle', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
           $(element).cycle({
               fx: 'fade',
               timeout: 10
           });
        }
    };
});

I have the above AngularJS and when I run my page the Console.Log shows [cycle] terminating; too few slides: 0 and then it shows the Get Request after.

How would I be able to run the directive once the $http.get has finished?

2 Answers 2

1

try doing this

<div cycle ng-if="drinks"></div>

that way element that contains directive will be compiled in browser only when the drinks are available

Sign up to request clarification or add additional context in comments.

Comments

0

There are two things you can use

  • ng-cloak

  • ng-show and ng-hide and custom scope property

Also consider using animation instead of creating manual animation within directive

1 Comment

The problem is that the directive is running right away. How would this work when there is no data?

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.