javascriptangularjsng-bind-html

Call a js function on an html snippet rendered using ngBindHtml


I'm fetching some html content that I want to display in an Angular widget. I'm using ng-bind-html to display this html content in the controller. Once this html content has rendered I want to call a js function that can modify some parts of this html content(Hide/show using classes in the content). There is no trigger for this function I want to call this function as soon as the html is rendered.

I tried calling the js function after the ngBindHtml object is initialized which no surprise doesn't work.

Is there some way to find out(an event or something like that) when the html content has rendered.

I don't have any sharable code right now.


Solution

  • Try calling your function inside $timeout:

    $timeout(function() {
        // your code
    });
    

    $timeout will add a new event to the browser event queue where the rendering process is in.