I am trying to use AngularJS to detect bootstrap environment. This is my code:
angular.module("envService",[])
    .factory("envService", envService);
    function envService($window){
        return env();
        ////////////
        function env(){
            var w = angular.element($window);
            var winWidth = w.width();
            if(winWidth<768){
                return 'xs';
            }else if(winWidth>=1200){
                return 'lg';
            }else if(winWidth>=992){
                return 'md';
            }else if(winWidth>=768){
                return 'sm';
            }
        }
    }
The function works and return the value based on the window size. However, it will always return the same environment even if the window size is changed. How can I fix it?
                        
You need to watch for the window resize event.