📜  如何使用AngularJS获取视口的尺寸?

📅  最后修改于: 2021-05-13 19:31:39             🧑  作者: Mango

在本文中,我们将看到如何在AngularJS中获取视口的尺寸。

方法:

  • 方法是使用clientWidth和innerWidth属性。
  • 这些值的最大值应分别为宽度和高度。

示例1:在此示例中,高度和宽度以像素为单位计算。

HTML
 

  

    
  
    
 
  

    

           GeeksForGeeks       

                

        How to get the dimensions of the          Viewport in AngularJS     

       
           
                         

            Height of viewport = {{height}}px             
            Width of viewport= {{width}}px             
        
      
        


HTML
 

  

    
  
    
 
  

    

           GeeksForGeeks       

           

        How to get the dimensions of the Viewport in AngularJS     

       
           
                         
            
            Height of viewport = {{height * 2.54 / 96}}cm             
            Width of viewport= {{width * 2.54 / 96}}cm             
        
      
        


输出:

示例2:在此示例中,高度和宽度以厘米为单位计算。

的HTML

 

  

    
  
    
 
  

    

           GeeksForGeeks       

           

        How to get the dimensions of the Viewport in AngularJS     

       
           
                         
            
            Height of viewport = {{height * 2.54 / 96}}cm             
            Width of viewport= {{width * 2.54 / 96}}cm             
        
      
        

输出: