Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@angular/flex-layout How To: different class based on screensize?

Is there a way to have @angular/flex-layout change the class based on screen size?

I know I can do this:

<div fxFlex="grow" fxLayout="row" fxLayout.xs="column">

and this:

<div fxFlex="22"    fxFlex.md="10px" fxHide.lg>

etc.

I'd like to be able to do something like this:

<div class="myWideClass" class.xs="myNarrowClass">

Is there any way to do this kind of thing - change the class based on the screen width?

Thanks!

like image 937
buzzripper Avatar asked Nov 19 '17 18:11

buzzripper


People also ask

Is Angular Flex layout responsive?

Using Angular Flex layouts, we can create any HTML layouts that are responsive on all devices.

How do I use Angular Flex layout?

Installation of Angular Flex-LayoutUse the following command to use Angular Flex layouts in your projects. After installing flex layout we need to import flexLayoutModule in our app. module. ts file as shown below.

Is Angular Flex layout deprecated?

A core principle of Angular is the separation of concerns. By deprecating flex-layout in favor of CSS, we continue to guide users towards more readable and maintainable code.

What is fxLayout SM?

fxLayout is a directive used to define the layout of the HTML elements. i.e., it decides the flow of children elements within a flexbox container. fxLayout should be applied on the parent DOM element i.e., flexbox container. And fxLayout directive case sensitive.


1 Answers

If someone is looking for a way to add a class if it is bigger than xs for example, you could do:

<div [ngClass.gt-xs]="'myNarrowClass'"></div>
like image 130
Tom el Safadi Avatar answered Sep 29 '22 10:09

Tom el Safadi