AngularJs data binding in ajax html response

前端 未结 1 1289
感动是毒
感动是毒 2020-12-14 13:52

I\'m using python/django as a backend with complex forms structure.
I got an angular controller which makes and request to get a suitable form. I found a django-angular

相关标签:
1条回答
  • 2020-12-14 14:01

    Create directive to $compile your html.

    angular.module("app").directive('compilehtml', ["$compile", "$parse", function($compile, $parse) {
        return {
            restrict: 'A',
            link: function($scope, element, attr) {
                var parse = $parse(attr.ngBindHtml);
                function value() { return (parse($scope) || '').toString(); }
    
                $scope.$watch(value, function() {
                    $compile(element, null, -9999)($scope); 
                });
            }
        }
    }]);   
    

    Then add this directive

    <div ng-bind-html="form" compilehtml></div>
    

    DEMO

    0 讨论(0)
提交回复
热议问题