我试图使用超时来将调整大小的触发器偏移几毫秒,以便在我最大化窗口时它起作用。不幸的是我得到的未定义不是一个函数:
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);
});
}
}
}]);
答案 0 :(得分:3)
而不是
adminLayoutDirectives.directive('viewFrame', [function($scope, $rootScope, $timeout)
DO
adminLayoutDirectives.directive('viewFrame', ['$scope', '$rootScope', '$timeout', function($scope, $rootScope, $timeout) {
享受