我是AngularJS的新手.我想创建网格(使用ng-grid),其高度取决于窗口高度,即.$('.gridStyle').height($(window).height() - 100);
我写了指令:
app.directive('resize', function($window) {
return function(scope, element) {
function applyHeight() {
scope.height = $window.innerHeight;
$('.gridStyle').height(scope.height - 100);
}
angular.element($window).bind('resize', function() {
scope.$apply(function() {
applyHeight();
});
});
applyHeight();
};
});
Run Code Online (Sandbox Code Playgroud)
这在我调整浏览器窗口大小时很有效,但是第一次加载网站时不应用样式.我在哪里可以将代码放入高度?