user4474387
user4474387

Reputation:

Insert plain HTML into template

I use AngularJs 1.4 and I need to insert plain HTML which I receive from $http.get() into my template as HTML tags like jQuery inserts plain HTML into DOM as tags.

Conroller code:

var onLoadUrl = function( data ){

    $scope.joomlaComponent = data;

}

joomlaComponent.loadUrl( $location.absUrl(), true ).then( onLoadUrl );

Template:

<script type="text/ng-template" id="joomla-component.tpl">
    <div class="uk-grid uk-margin-large">
        {{joomlaComponent}}
    </div>
</script>

Now it insert it as plain text but I need to have it like HTML tags inserted into a document's DOM.

Upvotes: 0

Views: 114

Answers (1)

Iso
Iso

Reputation: 3238

First off, you need to call $scope.$evalAsync() in your onLoadUrl function to trigger a digest cycle. Then, use ng-bind-html="joomlaComponent" instead of {{ joomlaComponent }}.

Upvotes: 1

Related Questions