npm i ngx-responsive-elements
Import the module via
import { NgxResponsiveElementsModule } from 'ngx-responsive-elements';
and add NgxResponsiveElementsModule to your module's imports
@NgModule({
imports: [..., NgxResponsiveElementsModule],
})
export class YourModule {}
You can use the directive on any element you want.
Define a sizeMap object. The key is the lowest pixel value of the element's width and the value is the css class that should get applied.
Example:
const sizeMap = { 300: 'small', 500: 'medium', 700: 'large' };
<div ngxReResponsiveElement [sizeMap]="sizeMap"></div>
From 300px element's width to 499px the class 'small' will be applied. From 500px element's width to 699px the class 'medium' will be applied. From 700px element's width onwards the class 'large' will be applied.
For widths lower than 300px, the defaultCssClass will be applied.
Define the css class your element should have when the element's size is smaller than the smallest key in your sizeMap.
If you don't set the defaultCssClass, it defaults to 'default'.
Example:
const defaultCssClass = 'test';
<div ngxReResponsiveElement [defaultCssClass]="defaultCssClass"></div>
This project was generated with Angular CLI version 8.2.2.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app
will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can
also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the
dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via
Karma.
Run ng e2e
to execute the end-to-end tests via
Protractor.
To get more help on the Angular CLI use ng help
or go check out the
Angular CLI README.