javascript 如何读取文本文件并将其显示在 html (angularjs) 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31598135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 14:02:20  来源:igfitidea点击:

how to read a text file and display it in html (angularjs)

javascriptangularjs

提问by user3137376

I am using angularjs and i have a terms of use document in a text file which i was to render into html. Any recommendations on how to read that text file and display it using html or display it to the user? Thanks

我正在使用 angularjs 并且我在一个文本文件中有一个使用条款文档,我要将其呈现为 html。关于如何读取该文本文件并使用 html 显示它或向用户显示它的任何建议?谢谢

回答by charlietfl

Simplest way is using ng-include. If you need to use the line breaks in the text file within your view wrap in a <pre>tag

最简单的方法是使用ng-include. 如果您需要在视图中的文本文件中使用换行符,请在<pre>标签中换行

<h3>Terms</h3>
<ng-include src="'terms.txt'"></ng-include>

OR

或者

<pre ng-include src="'terms.txt'"></pre>

DEMO

DEMO