简体   繁体   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

to know the width of div 知道div的宽度

i want to know the width of the within the template ,and store in the variable how can i achieve that 我想知道模板内的宽度,并存储在变量中我该如何实现

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

you can have the link function to get access to the element using which you can get the width of the div. 你可以使用link函数来访问元素,使用它可以获得div的宽度。

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

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

You can do this with angular.element eg: 您可以使用angular.element执行此操作,例如:

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

or if you have jQuery loaded 或者如果你加载了jQuery

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么知道div元素的宽度 - how i can know the width of div element 我想要一个切换div elemenet,以将底层内容与z-index重叠。 我该如何实现? - I want a toggling div elemenet, to overlap the underlaying content with z-index. How can I achieve this? 如何在HTML页面中正确存储HTML模板? - How can I correctly store a HTML template within a HTML page? 如何在数组中存储对变量的引用? - How can I store reference to a variable within an array? 我想知道如何在后面的代码中访问模态表单元素。我也想知道如何在模态表单上应用jquery验证器 - I want to know that how can i access my modal form elements in my code behind .Also I want to know how can I apply jquery validator on modal form 如何在变量中存储包含哈希标记的完整URL? - How can I store a full url that contains a hashmark within a variable? 如何在Meteor模板中共享变量? - How can I share a variable within a Meteor template? 如何在我的 CSS 或 Tailwind class 中设置可变宽度? - How can I set a variable width in my CSS or Tailwind class? 我如何捕获哪个号码 <div> 在我的容器内被点击 <div> 并将其存储在变量中 - how do i capture which number <div> got clicked on inside my container <div> and store it in a variable 如何动态地向我的角度应用程序添加动态指令? - How can I add dynamic directives to my angular app on the fly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM