首页 > 解决方案 > 如何在html中呈现多行字符串变量

问题描述

我需要在我的 Angular 4 视图 (HTML) 中显示一个多行变量。问题是我将 HTML 标记 br/ 放置在我希望字符串中断并从新行开始的位置,但 br/ 显示为文本。我试过 br/, \r br /, ...这些都不起作用。以下是文本示例:

文件内容

<br /> xxxxx connects buyers of automotive parts and services with providers of those services. This document outline what information we collect from both the buyers and providers and how we handle this information, our privacy policy.<br />1. Scope of this Privacy Policy:<br /> xxxxxx and its parents, subsidiaries, representatives, affiliates, officers and directors (collectively, 'PuppyDog') values the privacy of individuals who use our application, websites, and related services. This privacy policy (the 'Privacy Policy') explains how we collect, use, and share information from xxxxxxx users (('Users'), comprised of both buyers of automotive parts and services and providers of those services.<br />2. Information We Collect-<br />Personal Information-<br />Buyers Registration Information. When you register as a.......

我应该指出,来自 JSON 文件的变量使用数据绑定来显示 HTML 中的值。我将不胜感激任何建议。

标签: javascripthtmlangular

解决方案


要使用多行变量,请使用符号 `

要使用新字符串,请使用\n

像这样:

var text=`\n
 xxxxx connects buyers of automotive parts and services with providers of those services. This document outline what information we collect from both the buyers and providers and how we handle this information, our privacy policy.\n
 1. Scope of this Privacy Policy:\n
 xxxxxx and its parents, subsidiaries, representatives, affiliates, officers and directors (collectively, 'PuppyDog') values the privacy of individuals who use our application, websites, and related services. This privacy policy (the 'Privacy Policy') explains how we collect, use, and share information from xxxxxxx users (('Users'), comprised of both buyers of automotive parts and services and providers of those services.\n
 2. Information We Collect-\n
 Personal Information-\n
 Buyers Registration Information. When you register as a.......
`;

alert(text);


推荐阅读