0

I am dealing with headers and footers in angularjs. I have different header for mobile view and webview. How do I conditionally handle headers in angularjs depending on the window width.

Right now I am doing that with jquery as follows:

if (window.matchMedia('(max-width: 768px)').matches) {
 //hidewebheader;
//show mobileheader;
} else {
  //hidemobileheader;
  //showwebheader;
}

How do i achieve this in angularjs. There is one file of header.html which has 2 different markups for web and mobile headers.

Nikita Jajodia
  • 4,220
  • 3
  • 21
  • 29

1 Answers1

1

inject $window. I know there's $window.innerHeight so I GUESS there's $window.innerWidth (didn't try it). use $scope.$watch on the width and use ng-if to decide what header you are showing right now.

by the way, we use bootstrap and there is a good way to do it there with css only solution. I think bootstrap uses @media behind the scene. I'm not sure that you need to use angular or js for your problem. use css.

Yonatan Vainer
  • 453
  • 5
  • 15