Lately, I've been struggling to figure out how to dynamically change the content of a directive in AngularJS.
Initially, in my HTML, there is a parent directive with a child directive inside. Every now and then, I need to update the content of the parent directive, but the child directive that I'm trying to insert isn't being initialized by AngularJS. To better illustrate my issue, I created a JSFiddle: http://jsfiddle.net/koj2e1th/2/
When I try to update the content using $timeout, the directive isn't properly initialized:
$timeout(function(){
html = '<child-dir>TIMEOUT</child-dir>'
scope.content = $sce.trustAsHtml(html)
}, 2500)
I attempted to use $compile (as suggested in other posts) but couldn't get it to work correctly. Can someone please explain how to make $compile function in this scenario and ensure that my child-dir
gets rendered properly?
Thank you in advance!