I followed the solution at Angular UI, Bootstrap Navbar Collapse and Javascript and used an ng-click on the list items to make sure the menu collapses when a menu item is clicked (otherwise it just stays open) on mobile devices.
However, I noticed that in the large screen view there is a flicker effect on the menu when the list items are clicked because a menu collapse toggle is triggered.
to fix that, I am using the following function in my controller to ensure that the click even is triggered only on the mobile view:
$scope.toggleCollapse = function(){
if($window.innerWidth < 768){
$scope.navbarCollapsed = !$scope.navbarCollapsed
}
}
But I am pretty sure that it is bad practice to have the screen size used like that inside the controller.
How can I achieve this in a more angularjs best-practice way?