0

I'm in the process of refactoring some code written with Angular.js, mostly as an attempt to prevent the braces from rendering whilst everything loads. The original code looks like:

<p class="summary">{{ feature.articleSummary }}<a ng-href="/feature/reader/?articleId={{feature.articleId}}" class="summary">...(more)</a></p>

And then attempted refactoring to:

<p class="summary" ng-bind="feature.articleSummary"><a ng-href="/feature/reader/?articleId={{feature.articleId}}" class="summary">...(more)</a></p>

However, this loses the embedded <a> element. Is it possible to bind an element within a binding? Or would it be better to create a directive to handle a new template? Or is there a better way of handling this?

1 Answer 1

0

You should first use ng-bind-html instead of the simple ng-bind and then you should create a filter so sanitise the html:

yourApp.filter("sanitize", ['$sce', function($sce) {
    return function(htmlCode){
        return $sce.trustAsHtml(htmlCode);
    }
}]);

So that your code goes like this:

<p class="summary" ng-bind-html="feature.articleSummary | sanitize">...</p>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.