How can I get the width of an element using AngularJS?

后端 未结 2 498
说谎
说谎 2021-02-02 10:03

I realise I can use jQuery to get the width of an element, but I\'m curious; is there a way to do so using AngularJS?

2条回答
  •  别跟我提以往
    2021-02-02 10:26

    If you've been scratching your head like me over all these suggestions and they don't work, i found i had to set a timeout. I'm not sure why, maybe because i'm using material design attributes on my divs.

    setTimeout(function(){
         var divsize = angular.element(document.getElementById('fun_div')).prop('offsetWidth');   
         console.log('Width of fun_div: ' + divsize);
        },50);
    

提交回复
热议问题