I was trying to make a div resize when the window resizes, after looking around, it seems that using a directive was the best solution.
Template:
<div elHeightResize ng-view ng-style="{ height: windowHeight }"></div>
Directive:
myApp.directive('elheightresize', ['$window', function($window) {
return {
link: function(scope, elem, attrs) {
scope.onResize = function() {
var header = document.getElementsByTagName('header')[0];
elem.windowHeight = $window.innerHeight - header.clientHeight;
}
scope.onResize();
angular.element($window).bind('resize', function() {
scope.onResize();
})
}
}
}])
While I can log elem.windowHeight
in scope.onResize
, it doesn't seem to apply it to ngStyle
Am I still overlooking something?
EDIT:
<div ng-view resize style="height: {{ windowHeight }}px">
This solution seems to work, still interested into why using ngStyle
wasn't working.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…