Basically, I want to measure the width of an element after angular has processed the DOM. So I would like to use $ timeout for this, but it keeps getting me errors.
HTML
<div ng-app="github"> <ul mynav> <li ng-repeat="nav in navItems">{{nav.name}}</li> </ul> </div> </div>
CSS
ul,li { display:inline-block; } li { margin-right:1em; }
Js
(function() { angular.module('github', []) .directive('mynav', function($window) { return { restrict: 'A', link: function(scope, element, attrs, timeout) { scope.navItems = [{ "name": "home" }, { "name": "link1" }, { "name": "link2" }, { "name": "link3" }]; timeout(function() { console.log($(element).width()); }) } } }); })();
source share