简体   繁体   English

Angular正在从HTML标签中剥离属性

[英]Angular is stripping attributes from HTML tags

Edit 2 : The issue was in fact with the sanitizer stripping my tags. 编辑2 :问题实际上是与消毒剂剥离我的标签。 The solution was passing it through a simple function : 解决方案是通过一个简单的函数传递它:

self.markTrusted = function (markup) {
    return $sce.trustAsHtml(markup);
};

This allows marks it as trusted to Angular and will leave in my attributes. 这允许将其标记为受Angular信任,并将保留在我的属性中。 This did not, however, fix my linking problem, but that is outside the scope of this question. 但是,这并不能解决我的链接问题,但这不在此问题的范围内。

Edit: Think I may have found the problem. 编辑:认为我可能已经找到了问题。 The second anchor is actually <a name="someSection"></a> . 第二个锚点实际上是<a name="someSection"></a> I think the sanitizer may be catching it and removing it. 我认为消毒剂可能会抓住并清除它。 Is there any way to tell the sanitizer to let it through? 有什么办法告诉消毒剂通过吗?

I am using Angular version 1.5 我正在使用Angular 1.5版

I am trying to implement anchor links in my site. 我正在尝试在我的站点中实现锚链接。 I found several answers on here that indicated that the following code should work with Angular to link within my page: 我在这里找到了几个答案,这些答案表明以下代码应与Angular一起在我的页面内进行链接:

<a href="#someSection" target="_self">Text</a>

<a id="someSection"></a>

I have that code being passed (embedded in the my other HTML and content) to the front end by my API as a string, and I am displaying it on page like this: 我将我的API的代码作为字符串传递(嵌入到我的其他HTML和内容中)到前端,并且正在这样显示在页面上:

<div ng-bind-html="content.markup"></div>

The problem is though that for some reason my anchor tag is being stripped so now I have 问题是尽管由于某种原因我的锚标签被剥离,所以现在我有了

<a href="#someSection" target="_self">Text</a>

<a></a>

which obviously doesn't work. 这显然是行不通的。 Can anyone give me any ideas as to why that second anchor tag would be getting stripped of its attributes? 谁能给我任何关于为什么第二个锚标签被剥夺其属性的想法?

尝试将href添加到锚标记中:id =“ someSection” href =“#” / a,或者如果您不希望它可单击,请改用span或p标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM