簡體   English   中英

我想知道的寬度 <div> 在我的指令模板中,並存儲在變量中我該如何實現

[英]i want to know the width of the <div> within my directives template ,and store in the variable how can i achieve that

知道div的寬度

我想知道模板內的寬度,並存儲在變量中我該如何實現

 pp.directive('skillSlider',function() { return{ template:'<div class="progress"></div>' } }); ---------- how to calculate the width of the div inside the directive template 

你可以使用link函數來訪問元素,使用它可以獲得div的寬度。

pp.directive('skillSlider',function()
    {
       return{
              template:'<div class="progress"></div>',

              link:function (scope, element, attrs) {
                console.log(element.width());
               })   
    }
 });     

您可以使用angular.element執行此操作,例如:

angular.element(document.getElementById(id)).clientWidth;
angular.element(document.querySelectorAll('.class')[0]).clientWidth;

或者如果你加載了jQuery

angular.element($('#id').width();
angular.element($('.class')[0]).width();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM