There surely is. Generally, you DON'T wanna use jQ in AngularJS ever, and vanilla only for things not provided by AngularJS. Here you are doing the binding to view. That surely is something AngularJs offers, being the MVsomething framework.
Reason? In nonspecific and simple terms, AngularJS has its own ways which ensure neat things like data binding etc if you don't obey by its rules you will most likely break the neat things you get.
Here is a demo of how to do this in modern AngularJS:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p ng-bind-html="myText"></p>
</div>
<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
$scope.myText = "My name is: <h1>John Doe</h1>";
});
</script>
It is quite simple. You define HTML as a string, bind that to the scope like any other data you want accessible in the view and then simply use the ng-bind-html
directive to inject HTML into element where you are using the directive.
Neat, simple, safe and result will work as any other template statically written, you can band data from and to it with no additional hassle, the digest cycle will also work as usual.