简体   繁体   English

Angular 打开新窗口并显示 xml

[英]Angular open new window and display xml

I would like to open a new window after a click event and show an xml structure.我想在单击事件后打开一个新窗口并显示一个 xml 结构。 I do not want that browser interpret my xml.我不希望该浏览器解释我的 xml。

I tried with this:我试过这个:

window.open('data:text/xml;charset=utf-8,<?xml version="1.0" encoding="UTF-8"?><RootTag>'+xml+'</RootTag>', "", "_blank")

with chrome this do not work.使用 chrome 这不起作用。

You have two questions here你在这里有两个问题

  1. To open a window either use a popup / modal control (for example NgBootstrap Modal ) or use angular routing to navigate to a different page.要打开窗口,请使用弹出/模态控件(例如NgBootstrap Modal )或使用角度路由导航到不同的页面。

  2. To just show xml write it in interpolation.只显示 xml 用插值写它。 Something like this.像这样的东西。

 <div style="white-space:pre; font-size:12px; font-family:monospace;">{{getXML()}}</div>

and in the component,在组件中,

 getXML() { return "<RootTag>xml</RootTag>"; }

Please find sample code .请查找示例代码

I solved this problem with this code in the component.ts我在 component.ts 中用这段代码解决了这个问题

    let blob = new Blob([text], {type: 'text/xml'});
    let url = URL.createObjectURL(blob);
    window.open(url);
    URL.revokeObjectURL(url);

This open a new window with the view just for xml.这将打开一个新窗口,其中包含仅用于 xml 的视图。

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

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