如何解决AngularDart“忽略<style>,因为在没有适当清理的情况下将该元素绑定到模板中是不安全的”

时间:2019-01-09 01:28:29

标签: angular dart angular-dart

我的template.html包含许多html和内联css,并且全部混合使用。这是因为最终它是用于电子邮件的。

Angular不喜欢这样,并向我发出此警告:

  

忽略,因为在没有适当清理的情况下将此元素绑定到模板是不安全的。在将来的AngularDart版本中,这可能会成为错误。有关详细信息,请参见 https://webdev.dartlang.org/angular/guide/security 。       

我在文档中看到它建议使用“ bypassSecurityTrustHtml”或类似内容,但是涉及到以下内容:

  style = sanitizer.bypassSecurityTrustHtml('带有CSS样式的html代码');
 

而且我不能在新行中粘贴大量的html / css代码,例如在其中插入单个字符串。

那我该怎么做以阻止Angular忽略我的样式标签?

2 个答案:

答案 0 :(得分:1)

在Dart中,您可以使用'''string on multiple lines'''将html / style / css代码放入并放置在bypassSecurityTrustHtml函数中。

答案 1 :(得分:1)

没有什么可以阻止您传递多行字符串而不是单行字符串,因为除了多行字符串包含\n\r\n之外没有什么区别。

Dart提供了几种编写多行字符串的方法。

'1st line\n2nd line' 

'1st line\n' + '2nd line'

'1st line' 
'2nd line'

'''
1st line
2nd line
'''

var buffer = StringBuffer();
buffer.writeln('1st line');
buffer.write('2nd line');
buffer.toString();