AngularJS在$http get完成后启用指令


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
           });
        }
    };
});

我有上面的AngularJS,当我运行我的页面时,Console.Log显示[cycle] terminating; too few slides: 0,然后显示Get Request

我如何能够运行指令一旦$http.get已经完成?

试试

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

有两种用法

  • ng-cloak

  • ng-showng-hide和自定义scope属性

还可以考虑使用动画而不是在指令

中创建手动动画。

最新更新