In a directive I need to have the width of an element, however this element is created in a ng-repeat
. So when the code inside my link
function runs, ngRepeat is not yet executed. I tried to delay things using $timeout
but that didn't help
JS:
link: function (scope, element) {
$timeout(function () {
var width = $(element.find('li')).width(); // the li elements do not exist
});
}
HTML:
<ol>
<li ng-repeat="item in items">
<my-item>.....</my-item>
</li>
</ol>
I cannot use the <ol>
element, because the <my-item>
has styles like margins/paddings.
Any suggestions ?