$timeout "Undefined is not a function"



我正在尝试使用超时将调整大小触发器偏移几米利秒,以便在我最大化窗口时它可以工作。不幸的是,我没有得到定义不是一个函数:

angular.element(window).resize(function() {
    var newBreakpoint = getBreakpoint();
    var previousBreakpoint = null;
    if (newBreakpoint != currentBreakpoint) {
        previousBreakpoint = currentBreakpoint;
        currentBreakpoint = newBreakpoint;
    }
    var currentWindowWidth = window.innerWidth;
    var broadcastResize = function() {
        $scope.$broadcast('windowResize', currentBreakpoint, previousBreakpoint, currentWindowWidth);
    }       
    $timeout(broadcastResize, 150);
}); 

在此指令中:

adminLayoutDirectives.directive('viewFrame', [function($scope, $rootScope, $timeout) {
    return {
        controller: function($scope, $element) {
            var width = function() {
                return $element.width();
            } 
            var getBreakpoint = function() {
                var windowWidth = window.innerWidth;
                if(windowWidth < 768) {
                    return 'extra small';
                } else if (windowWidth >= 768 && windowWidth < 992) {
                    return 'small';
                } else if (windowWidth >= 992 && windowWidth < 1200) {
                    return 'medium';
                } else if (windowWidth >= 1200) {
                    return 'large';
                }                   
            }
            currentBreakpoint = getBreakpoint();
            angular.element(window).resize(function() {
                var newBreakpoint = getBreakpoint();
                var previousBreakpoint = null;
                if (newBreakpoint != currentBreakpoint) {
                    previousBreakpoint = currentBreakpoint;
                    currentBreakpoint = newBreakpoint;
                }
                var currentWindowWidth = window.innerWidth;
                var broadcastResize = function() {
                    $scope.$broadcast('windowResize', currentBreakpoint, previousBreakpoint, currentWindowWidth);
                }       
                $timeout(broadcastResize, 150);
            }); 
        }
    }
}]);

而不是

adminLayoutDirectives.directive('viewFrame', [function($scope, $rootScope, $timeout) 

adminLayoutDirectives.directive('viewFrame', ['$scope', '$rootScope', '$timeout', function($scope, $rootScope, $timeout) {

享受

相关内容

最新更新