简体   繁体   English

9 如何显示Angular中一个文件的内容?

[英]How to display the content of a file in Angular 9?

I have an Angular App, and the user uploads two files there, json and xml. What I want to do is show the contents of the file.我有一个 Angular 应用程序,用户在那里上传了两个文件,json 和 xml。我想做的是显示文件的内容。 I have tried one approach, processing the file line by line and adding it to a string and then show the string.我尝试了一种方法,逐行处理文件并将其添加到字符串中,然后显示字符串。 But that way I lose the indentation and other things too.但那样我也失去了缩进和其他东西。 Is there any way I can show the uploaded file directly without having to go all the trouble.有什么办法可以直接显示上传的文件,而不必麻烦 go。 And I have one more thing to do, I have a list of line number and I want to maybe add custom color to that line numbers.我还有一件事要做,我有一个行号列表,我想为该行号添加自定义颜色。 eg [2,3,4] is the list of line number, and so in the uploaded file, I would like to color line numbers 2,3,4 as red.例如[2,3,4]是行号列表,所以在上传的文件中,我想将行号 2,3,4 设置为红色。 How can I do all this?我怎样才能做到这一切?

The iFrame tag is often a good way to simply display files, but I don't have experiences in using the iFrame tag with JSON or XML files and it would not directly solve your problem of modifying them... iFrame 标签通常是简单显示文件的好方法,但我没有将 iFrame 标签与 JSON 或 XML 文件一起使用的经验,它不会直接解决您修改它们的问题......

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

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