Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to output html code as content in angular

Shulou Source: shulou.com Published: 2022-05-31 12:48:28 09月24日 Update

This article introduces the relevant knowledge of "how to output html code to content in angular". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Method one

To output content without html, it takes two steps

1 use the $sce.trustAsHtml (); method to convert the data to unwrapTrustedValue data.

$scope.aaa = $sce.trustAsHtml ("html Code")

2 ng-bind-html output

Method 2 filter filter

Based on the method of $sce.trustAsHtml (), a filter is constructed to filter.

Angular.module ('app', []) .filter ("showAsHtml", function ($sce) {return funciton (input) {retrun $sce.trustAsHtml (input);}})

When you use it, you can add a filter directly to the data.

When using $scr.trustAsHtml (), you must use the form of ng-bind-htm='' instead of {{}}.

This is the end of "how to output html code to content in angular". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Content output method code data filter time more knowledge practicality achievement next dilemma reality form situation article case editor website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Shulou Technology NVidia Apple