Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- app.directive('html', ['$timeout','$window', function ($timeout, $window) {
- return {
- restrict: 'A',
- link: function (scope, element, attrs) {
- function parseHtml(tries) {
- // a sanity check, just in case we reuse this function as a handler,
- // e.g. for `orientationchange`
- if (isNaN(+tries)) {
- tries = attrs.maxTries || 10;
- }
- if (tries > 0) {
- $timeout(function() {
- var width = parseInt($window.getComputedStyle(element[0]).width, 10);
- if (width) {
- // if width is computed, the element is ready to be manipulated
- //parse html and scripts from snippet
- element.html(attrs.html);
- // ...
- } else {
- // otherwise, the element is not ready, so decrement the tries,
- // wait a bit, and try again:
- parseHtml(tries - 1);
- }
- }, attrs.msDelay || 100);
- } else {
- // if we got here, we've exhausted our tries, so we probably
- // want to log or warn or throw here.
- }
- }
- parseHtml(attrs.maxTries);
- }
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement