Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an angular template that I would like to be able to access the processed HTML from within a javascript function.

If for example the template was under a templateUrl

 "/scheduler/tooltip.html"

and the HTML was something like

 <div>{{tip.Name}}</div>

is the a way to call and process that template without using all of the directive overhead? eg:

 angular.$compiletemplate('/scheduler/tooltip.html', { tip: { Name: "foo" }});

In this case I'm specifically trying to solve the problem of a third party library appending a DOM element outside of the existing angular scope - so I seem to be unable to make the HTML a directive.

If there is a way to make sure a directive will work anywhere on the page that might also be useful.

share|improve this question
    
Once your directive compiles, you can do something like element.html() to get the result –  SoluableNonagon Jul 29 '14 at 16:50

1 Answer 1

Not sure if this helps:

app.directive('yourDirective', function ($interval) {

    var linker = function(scope, element, attrs) {

        var contents = element.html(); // this gets element HTML, initial HTML
        var currentContents = element.html();
        function updateContents() {
            currentContents = element.html();
            if(currentContents.length > contents.length)
                console.log('contents changed');
        }

        var interval = $interval(reportChange, 1000);

    }

}); 
share|improve this answer
    
as for a third party javascript running and inserting things into the DOM, you might just have to create an interval and have it report changes every few seconds –  SoluableNonagon Jul 29 '14 at 16:53
    
if you expect changes to variables on the scope in the directive, you can create a scope.$watch function to report the changes in html and see if something has been inserted –  SoluableNonagon Jul 29 '14 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.