我想知道模板内的宽度,并存储在变量中我该如何实现
pp.directive('skillSlider',function()
{
return{
template:'<div class="progress"></div>'
}
});
----------
how to calculate the width of the div inside the directive template
答案 0 :(得分:0)
你可以使用链接功能访问元素,使用它可以获得div的宽度。
pp.directive('skillSlider',function()
{
return{
template:'<div class="progress"></div>',
link:function (scope, element, attrs) {
console.log(element.width());
})
}
});
答案 1 :(得分:0)
您可以使用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();