title: Angular JS - How can I sanitize HTML in a controller?
body: <p>I'm trying to sanitize HTML in the controller as I'm trying to update the document.title dynamically with the title of the post. (I know that for SEO purposes this isn't recommended but I need to use it here)</p>
  
  <pre><code>$scope.prevTitle = "dynamic title gets pulled in here &amp;amp;"
  document.title = $scope.prevTitle 
  </code></pre>
  
  <p>For this example, I've just used a random HTML entity. I've tried the parseAsHtml method from the <a href="https://docs.angularjs.org/api/ng/service/$sce#parseAsHtml" rel="nofollow">official documentation</a> but I'm having no luck. I tried the following:</p>
  
  <pre><code>document.title = $sce.parseAsHtml($scope.prevTitle)
  </code></pre>
  
  <p>But no luck. The documentation suggests it needs to be used within a function. Any suggestions on how I would acheive this?</p>
  
  <p>A console log of the above ( console.log($sce.parseAsHtml($scope.prevTitle)) ) would return:</p>
  
  <pre><code>function (b,c){return e.getTrusted(a,d(b,c))} 
  </code></pre>