I am trying to render some html to the DOM that has AngularJS directives
HTML
<a ng-click="doThing()">hello 2015</a>
Except due to constraints in my application, I have to add it to the view from the controller. I am attempting to do this using the $compile service.
Controller.js
let html = '<a ng-click="doThing()">hello 2015</a>';
const compiledTemplate = $compile(html)($scope);
document.getElementById('wrapper').innerHTML = compiledTemplate[0].innerHTML;
$scope.doThing = function(){
console.log('it worked!');
}
View.html
<div id="wrapper"></div>
This renders the correct HTML but the directives dont work. Clicking on the link does not fire the doThing() function.
How can I compile and render a string representation of an AngularJS template such that all angular directives are functional?