以下指令导致无限摘要循环,我不知道为什么。关于如何重新编写代码的任何想法?
谢谢!
.directive('fitHeight', ['$window', '$timeout', '$location', function ($window, $timeout, $location) {
return {
restrict: 'A',
scope: true,
link: function (scope, element, attr) {
scope.docHeight = $(document).height();
var setHeight = function (newVal) {
var diff = $('header').height();
if ($('body').hasClass('layout-horizontal')) diff += 112;
if ((newVal-diff)>element.outerHeight()) {
element.css('min-height', (newVal-diff)+'px');
} else {
element.css('min-height', $(window).height()-diff);
}
};
scope.$watch('docHeight', function (newVal, oldVal) {
setHeight(newVal);
});
$(window).on('resize', function () {
setHeight($(document).height());
});
var resetHeight = function () {
scope.docHeight = $(document).height();
$timeout(resetHeight, 1000);
}
$timeout(resetHeight , 1000);
}
};