如何在使用angularjs进行http调用后运行owl carousel

时间:2015-02-04 17:26:04

标签: javascript jquery angularjs owl-carousel

您好我有一个投掷猫头鹰旋转木马指令,但我有一个工厂打电话给服务器获取我需要绘制容器旋转木马猫头鹰的数据,我怎么得到电话 $ http < / strong>完成我画的旋转木马猫头鹰?我的代码如下

指令

    app.directive('wrapOwlcarousel',['$timeout',function ($timeout) {  
    return {  
        restrict: 'E',  
        link: function (scope, element, attrs) { 

                 $timeout(function () {
                    scope.$emit('ngRepeatFinished');
                    var options = scope.$eval($(element).attr('data-options'));  
                    $(element).owlCarousel(options);
                    alert('carouel')
                });
        }  
    };  
]});

控制器

 app.controller('HomeController',[
    '$scope','$location','$timeout','Storage',function($scope,$location,$timeout,Storage){

        $timeout(function(){

            angular.element('#footer').css({
                'bottom' : '0'
            })

        },100);

        $scope.getClass = function(path) 
        { 
            if ($location.path().substr(0, path.length) == path){
                    if (path == "/" && $location.path() == "/") { return "active"; }
                    else if (path == "/") {  return ""; }

                    return "active" 

            } else { return "" } 
        }

        var items = Storage.has('posts');

        if(items){
            $scope.eventos = Storage.get('posts');
        }else{
            alert('no info')
        }


    }
]);

工厂

app.factory('EventFunctions',['$http','appSettings',function($http,appSettings){
    return {
        getAllPosts : function(){

            return $http.get(appSettings._url).then(function(result) {
               return result.data;
           });

        }
    }

}]);

感谢所有人!

1 个答案:

答案 0 :(得分:0)

我找到了答案!

我的指令有语法错误,这是我的新指令文件

app.directive('wrapOwlcarousel',['$timeout',function ($timeout) {  
    return {  
        restrict: 'E',  
        link: function (scope, element, attrs) { 

                 $timeout(function () {
                    var options = scope.$eval($(element).attr('data-options'));  
                    $(element).owlCarousel(options);
                });


        }  
    };  
}]);