Home Compile HTML string in AngularJS
Reply: 0

Compile HTML string in AngularJS

user1382 Published in April 26, 2018, 8:50 pm

So, a little background on this, I have an AngularJS/Ionic project that I'm attempting to do some improvement on, I'm placing all my HTML/JS/CSS into a database table, which in turn will be retrieved on a GET upon app start. HTML is then saved in a factory(also local storage). The goal, is to have an app that can be controlled from the HTML/JS/CSS that is within the Database table, so that we don't need to redeploy new versions for simple updates/fixes. Here's what I have tried:

The most successful method I used was using the below within the controller:

$scope.pageContent = $sce.trustAsHtml(htmlString)

and calling it within the HTML like below:

<div ng-bind-html="pagecontent"></div>

The only problem is, that it isn't compiling correct in a few ways - All my $scope values within the HTML aren't being linked to the parent controller scope.

My questions is: Is there a better way of handling this? I've seen a few people claiming using directives would be the way to go, but can't get a definitive answer on how to implement. Or, is how I'm moving forward working, and I'm just missing some key components... Any help on best way to implement would be greatly appreciated. Let me know if I left any information out, thanks!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30351 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO