[英]i want to know the width of the <div> within my directives template ,and store in the variable how can i achieve that
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.