javascript - 如何在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 中的值。我将不胜感激任何建议。
解决方案
要使用多行变量,请使用符号 `
要使用新字符串,请使用\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);
推荐阅读
- android - Android资源链接失败错误:属性'android:name'在
标记必须是有效的 Java 类名 - java - 错误:缺少 JavaFX 运行时组件 - JavaFX 11 和 OpenJDK 11 以及 Eclipse IDE
- json - 如何使用 Moshi 以 2 种不同的方式解析字段
- django - 在 Django 中将模型用作另一个模型的多个字段
- android - 访问 Firebase 功能时出现权限被拒绝错误
- codeigniter-3 - 哪个 CcAvenue PHP kit 4 文件将进入控制器和视图,在 Codeigniter
- vb6 - TreeView 控件 (comctl32.ocx) 不加载触摸屏服务
- javascript - 打印二叉树递归函数
- python-3.x - 如何使用 Anaconda Navigator 中的 Python 将文件 .py 转换为 .exe?(我应该在哪个命令提示符下编写安装代码?)
- c++ - 是否可以测试中止例程不返回?