使用angularjs删除编码的html

使用angularjs删除编码的html,angularjs,ng-bind-html,ngsanitize,Angularjs,Ng Bind Html,Ngsanitize,我在使用angularjs的ng bind html选项从文本中删除html代码时遇到问题 我的原文是这样的: '<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom

我在使用angularjs的ng bind html选项从文本中删除html代码时遇到问题

我的原文是这样的:

'<p><!--[if gte mso 9]><xml> <w:WordDocument>  <w:View>Normal</w:View>  <w:Zoom>0</w:Zoom>  <w:HyphenationZone>14</w:HyphenationZone>  <w:PunctuationKerning/>  <w:ValidateAgainstSchemas/>  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>  <w:Compatibility>   <w:BreakWrappedTables/>   <w:SnapToGridInCell/>   <w:WrapTextWithPunct/>   <w:UseAsianBreakRules/>   <w:DontGrowAutofit/>  </w:Compatibility>  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--></p><p><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabella normale"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}</style><![endif]--> <span mso-fareast-language:="" new="" style="font-size:10.0pt;line-height:115%;font-family:FuturaStd-Book;mso-fareast-font-family:" times="">'il senso del progetto riguarda soprattutto la costruzione di se stessi’. il progetto è per ag fronzoni il punto di partenza e di arrivo della sua ricerca, non è solo la realizzazione di un manufatto, ma è un processo di trasformazione dell’ambiente umano e dei suoi strumenti che può condizionare l’intera vita di un individuo.</span></p>'
但结果是:

<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--></p><p><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Tabella normale"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}</style><![endif]--> <span mso-fareast-language:="" new="" style="font-size:10.0pt;line-height:115%;font-family:FuturaStd-Book;mso-fareast-font-family:" times="">'il senso del progetto riguarda soprattutto la costruzione di se stessi’. il progetto è per ag fronzoni il punto di partenza e di arrivo della sua ricerca, non è solo la realizzazione di un manufatto, ma è un processo di trasformazione dell’ambiente umano e dei suoi strumenti che può condizionare l’intera vita di un individuo.</span></p>

'i我的目标是在东南部的科斯特鲁齐奥。弗朗佐尼公司的项目包括在农村地区和农村地区的合作、在农村地区的非独立实现、在个人生活条件下的环境和体制改革过程

这是一个代表我的问题的JSFIDLE:


我能做什么?

您需要绑定为不安全的html,如下所示:

<div ng-controller="MyCtrl">
  Hello, {{name}}!
  <div ng-bind-html-unsafe="my_html | to_trusted"></div>
</div>

你好,{{name}}!

NgSanitize无法将字符串转换为html。您可以使用jQuery实现这一点,如:

return $('<div/>').html(text).text()
return$('').html(text).text()

你想用它做什么?如果您需要正确的html,请返回服务器代码并找到它更改为HTMLentities的位置如果OP想要显示内容,它必须是有效的html firstHi rageandqq,感谢您的回复。angularjs在1.2.xxx版本之后不再支持ng bind html不安全。感谢您的建议。也许它不漂亮,但它确实有用!