我有以下几点:
.directive('resizer', ['$window', function ($window) { return { restrict: 'A', link: function (scope, elem, attrs) {
angular.element($window).on('load resize', function () {
var sectionHeight = angular.element(document.querySelector('#aboutContentSection'))[0].offsetHeight;
if (sectionHeight) {
if (elem[0].scrollHeight + sectionHeight < $window.innerHeight) {
elem.addClass('footerSetBottom')
} else if (elem[0].scrollHeight + elem[0].offsetTop >= $window.innerHeight) {
elem.removeClass('footerSetBottom')
}
}
});
}
}}])
然而,问题是当我使用ng-view时,当我转到一个新页面时,上面的load没有被调用。
我假设这是因为页面在技术上已经加载,它只是使用了新的ng-view。
所以我的问题是,我应该使用什么构造来进入代码,而不必刷新整个页面或调整窗口大小?
谢谢。
发布于 2016-05-30 01:39:57
为您的模块创建.run()函数,并在$rootScope上侦听事件$routeChangeSuccess
如下所示:
angular
.module('YourApp')
.run(runFn);
runFn.$inject = ['$rootScope','$window'];
function runFn($rootScope, $window){
$rootScope.$on('$routeChangeSuccess', function(){
angular.element($window).on('load resize', function () {
//... Some Logic
}
})
}https://stackoverflow.com/questions/37512869
复制相似问题