Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Making Angular project responsive using query listeners

Im looking for suggestions on how to make my angular project automatically detect and configure responsiveness.

Currently we are using a sort of matchmedia with queries such as "isMobile" etc. The project is responsive but doesnt detect a change in the responsiveness or size of the page automatically.

We want it to automatically detect a change in size that measures desktop, tablet or mobile and automatically update the responsiveness of the page to these configurations without needing to reload the page manually.

Any ideas or suggestions are welcome and please keep them coming cause this is a big project, thanks.

Example of a code piece we have in the project for this is down below.

    this.mobileQuery = media.matchMedia(`(max-width: ${MEDIA_BREAK_POINT}px)`);
    this._mobileQueryListener = () => changeDetectorRef.detectChanges();
    this.mobileQuery.addListener(this._mobileQueryListener);
    this.isMobile = this.service.isMobile;
    this.isTablet = this.service.isTablet;
    this.isDesktop = this.service.isDesktop;
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes of course:

enum DeviceSize='Mobile' | 'Tablet' | 'Desktop';
deviceSize$=new BehaviorSubject<DeviceSize>(DeviceSize.Desktop);
contructor(){
  this.initializeDeviceSize();
  fromEvent(window, 'resize')
      .pipe(
        startWith(null),
        debounceTime(1000),
      )
      .subscribe((c) => {
        this.onDeviceSizeChanged();
      });
}
initializeDeviceSize(){
 this.setDeviceSize();
}
onDeviceSizeChanged(){
 this.setDeviceSize();
}
setDeviceSize(){
 //check device size is which one of DeviceSize Enum
 if(isMobile){
   this.deviceSize$.next(DeviceSize.Mobile);
 }
 else if(isTablet)
 {
   this.deviceSizse$.next(DeviceSize.Tablet);
 }
 else {
   this.deviceSize$.next(DeviceSize.Desktop)
 }

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!