javascript - AngularJS wait for tag to load into DOM -
i'm adding google chart via angular directive page , add attribute element creates after it's loaded. best way ensure element exists before attempting add attribute?
from looking around seems directive have should work not:
.directive('vdfwidgetgooglechart', ['$timeout', function ($timeout) { return { restrict: 'e', //replace: true, templateurl: 'widgetgooglechart.html', link: function ($scope, elem, attrs) { function addtabindex () { elem.find('svg').attr({tabindex: -1}); } $timeout(addtabindex); }, scope: { chartobject: '=' } }
personally when doing charting easiest thing append attribute svg element, you're being angular aren't looking elements.
another option create controller , directive element svg requires controller. when have svg child of directive svg directive should called. (this guess haven't tried it)
<div controller-directive=".."><svg></svg></div>
then code have svg when controller exists parent.
or can adjust code svg every 100ms or until find it.
function addtabindex () { var svg = elem.find('svg'); if (svg.length != 0) svg.attr({tabindex: -1}); else $timeout(addtabindex, 100); } $timeout(addtabindex);
Comments
Post a Comment