简体   繁体   English

AngularJS ng-bind-html和组件

[英]AngularJS ng-bind-html and components

I'm using AngularJS ver. 我正在使用AngularJS版本。 1.6.8. 1.6.8。

I have a component I have built called icons. 我已经建立了一个称为图标的组件。 To incorporate it in a page I just add <icons></icons> and the component is inserted into the page. 要将其合并到页面中,我只需添加<icons></icons>并将组件插入页面中。

Now I have a scope variable that holds html, and part of that html is the previously mentioned code <icons></icons> . 现在,我有了一个包含html的作用域变量,并且该html的一部分是前面提到的代码<icons></icons>

When I use ng-bind-html it doesn't compile the component and instead just shows <icons></icons> as text. 当我使用ng-bind-html时,它不会编译组件,而只是显示<icons></icons>作为文本。

I have tried using angular-bind-html-compile ( link ) but that didn't help. 我曾尝试使用angular-bind-html-compile( link ),但这没有帮助。

All of the solutions I found seem to support angular pre made directives and not newly formed components. 我发现的所有解决方案似乎都支持角度预制指令,而不支持新形成的组件。

Happy to hear of any possible solutions. 很高兴听到任何可能的解决方案。

Did you do the following on your scope variable which holds the html code? 您是否对包含html代码的作用域变量执行了以下操作? This is a common mistake. 这是一个常见的错误。

$scope.trustAsHtml('<div>....')

But as mentioned before, without your code it is hard to figure out the problem. 但是如前所述,如果没有代码,很难找出问题所在。

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

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