Как заставить Angularjs что-то делать, если ширина экрана меньше 800 пикселей? мой похожий код jquery
if (screen.width < 800) {
alert('Less than 800');
}
else {
alert('More than 800');
}
Вот пример директивы, которая будет следить за размером окна. В ближайшее время: используйте $ watch и $ window.width()
app.directive('resize', function ($window) {
return function (scope, element) {
var w = angular.element($window);
scope.getWindowDimensions = function () {
return {
'h': w.height(),
'w': w.width()
};
};
scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
scope.windowHeight = newValue.h;
scope.windowWidth = newValue.w;
scope.style = function () {
return {
'height': (newValue.h - 100) + 'px',
'width': (newValue.w - 100) + 'px'
};
};
}, true);
w.bind('resize', function () {
scope.$apply();
});
}
})