0

In my app, a user triggers AngularJS to load an HTML containing Angular code from DB. After loading, Angular should compile and insert content to the div. I've used an SO answer to solve it https://stackoverflow.com/a/18157958/1392510. But it has to load seemingly big parts of page (more than 10-15 KBs) with this markup:

<div dynamic="markUp" ng-model="markUp"></div>

And here is dynamic directive:

app.directive('dynamic', function ($compile) {
    return {
        restrict: 'A',
        replace: true,
        link: function (scope, ele, attrs) {
            scope.$watch(attrs.dynamic, function(markUp) {
                ele.html(markUp);
                $compile(ele.contents())(scope);
            });
        }
    };
});

It seems like I am doing it wrong somewhere, because after insertion that dynamic div content duplicates the model content. Is there a more idiomatic way for doing this?

Community
  • 1
  • 1
Roman Dibikhin
  • 856
  • 4
  • 15

0 Answers0