Angular 6 Need to open new tab from componenent with new builded html (included input data)










0















Good day, everyone.



From the modal component that will input some data I need open new browser tab with resulted HTML that will contain formatted input data, example of code (i simplify it and try to use ng-template instead of one more component that should include resulted html):



@Component(
template:
'<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>n' +
'n' +
'<ng-template #hello>n' +
' <div>formatedData: someData.value</div>n' +
'</ng-template>n'
)
export class ValidationMessageComponent
@Input() someData: DataModel;

@ViewChild('hello') helloEl: ElementRef;

private openValidationWarningsInNewWindow(content: any)
const newWindow = window.open('about:blank', '_blank');
let hell = this.helloEl.nativeElement as HTMLElement;
newWindow.document.write(hell.innerText);
newWindow.document.title = 'Validation Warnings';
newWindow.document.close();




Sure, the way described in example doesn't work, at least I'm not able to get interHTML of nativeElement.
In new tab, i need just html representation (it's could be just simple HTML, but in this tab this html should included binded data)
Although, the way with [routerLink] and '_blank' target doesn't work, cause I need to transfer binding data.



Do you have any ideas?










share|improve this question
























  • I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

    – Nolik
    Nov 13 '18 at 9:29















0















Good day, everyone.



From the modal component that will input some data I need open new browser tab with resulted HTML that will contain formatted input data, example of code (i simplify it and try to use ng-template instead of one more component that should include resulted html):



@Component(
template:
'<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>n' +
'n' +
'<ng-template #hello>n' +
' <div>formatedData: someData.value</div>n' +
'</ng-template>n'
)
export class ValidationMessageComponent
@Input() someData: DataModel;

@ViewChild('hello') helloEl: ElementRef;

private openValidationWarningsInNewWindow(content: any)
const newWindow = window.open('about:blank', '_blank');
let hell = this.helloEl.nativeElement as HTMLElement;
newWindow.document.write(hell.innerText);
newWindow.document.title = 'Validation Warnings';
newWindow.document.close();




Sure, the way described in example doesn't work, at least I'm not able to get interHTML of nativeElement.
In new tab, i need just html representation (it's could be just simple HTML, but in this tab this html should included binded data)
Although, the way with [routerLink] and '_blank' target doesn't work, cause I need to transfer binding data.



Do you have any ideas?










share|improve this question
























  • I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

    – Nolik
    Nov 13 '18 at 9:29













0












0








0








Good day, everyone.



From the modal component that will input some data I need open new browser tab with resulted HTML that will contain formatted input data, example of code (i simplify it and try to use ng-template instead of one more component that should include resulted html):



@Component(
template:
'<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>n' +
'n' +
'<ng-template #hello>n' +
' <div>formatedData: someData.value</div>n' +
'</ng-template>n'
)
export class ValidationMessageComponent
@Input() someData: DataModel;

@ViewChild('hello') helloEl: ElementRef;

private openValidationWarningsInNewWindow(content: any)
const newWindow = window.open('about:blank', '_blank');
let hell = this.helloEl.nativeElement as HTMLElement;
newWindow.document.write(hell.innerText);
newWindow.document.title = 'Validation Warnings';
newWindow.document.close();




Sure, the way described in example doesn't work, at least I'm not able to get interHTML of nativeElement.
In new tab, i need just html representation (it's could be just simple HTML, but in this tab this html should included binded data)
Although, the way with [routerLink] and '_blank' target doesn't work, cause I need to transfer binding data.



Do you have any ideas?










share|improve this question
















Good day, everyone.



From the modal component that will input some data I need open new browser tab with resulted HTML that will contain formatted input data, example of code (i simplify it and try to use ng-template instead of one more component that should include resulted html):



@Component(
template:
'<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>n' +
'n' +
'<ng-template #hello>n' +
' <div>formatedData: someData.value</div>n' +
'</ng-template>n'
)
export class ValidationMessageComponent
@Input() someData: DataModel;

@ViewChild('hello') helloEl: ElementRef;

private openValidationWarningsInNewWindow(content: any)
const newWindow = window.open('about:blank', '_blank');
let hell = this.helloEl.nativeElement as HTMLElement;
newWindow.document.write(hell.innerText);
newWindow.document.title = 'Validation Warnings';
newWindow.document.close();




Sure, the way described in example doesn't work, at least I'm not able to get interHTML of nativeElement.
In new tab, i need just html representation (it's could be just simple HTML, but in this tab this html should included binded data)
Although, the way with [routerLink] and '_blank' target doesn't work, cause I need to transfer binding data.



Do you have any ideas?







html angular typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 13:19







Nolik

















asked Nov 13 '18 at 8:51









NolikNolik

52110




52110












  • I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

    – Nolik
    Nov 13 '18 at 9:29

















  • I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

    – Nolik
    Nov 13 '18 at 9:29
















I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

– Nolik
Nov 13 '18 at 9:29





I simplify my example, in best way i wanna use separate component instead of <ng-template #hello>

– Nolik
Nov 13 '18 at 9:29












1 Answer
1






active

oldest

votes


















2














First, you can beautify your template code wrapped by ``



and you don't need to add "n" any more



for Example:



`<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>`



Then let's fix your problem:



you can define some route and component to render the innerHTML



For Example:



You defined a route called '/dynamic_html'



and it's component's template like this:



<div [innerHTML]="MY_HTML"></div>


You can link to this route by window.open('/dynamic_html') or any other solution.



Don't forget to sanitize your html.



happy coding !






share|improve this answer























  • excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

    – Nolik
    Nov 13 '18 at 9:33











  • No, What I mean is you can pass your html data in other new route that you can parse it in that component.

    – junk
    Nov 13 '18 at 9:41











  • actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

    – Nolik
    Nov 13 '18 at 11:15











  • i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

    – Nolik
    Nov 13 '18 at 19:47










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277093%2fangular-6-need-to-open-new-tab-from-componenent-with-new-builded-html-included%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














First, you can beautify your template code wrapped by ``



and you don't need to add "n" any more



for Example:



`<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>`



Then let's fix your problem:



you can define some route and component to render the innerHTML



For Example:



You defined a route called '/dynamic_html'



and it's component's template like this:



<div [innerHTML]="MY_HTML"></div>


You can link to this route by window.open('/dynamic_html') or any other solution.



Don't forget to sanitize your html.



happy coding !






share|improve this answer























  • excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

    – Nolik
    Nov 13 '18 at 9:33











  • No, What I mean is you can pass your html data in other new route that you can parse it in that component.

    – junk
    Nov 13 '18 at 9:41











  • actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

    – Nolik
    Nov 13 '18 at 11:15











  • i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

    – Nolik
    Nov 13 '18 at 19:47















2














First, you can beautify your template code wrapped by ``



and you don't need to add "n" any more



for Example:



`<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>`



Then let's fix your problem:



you can define some route and component to render the innerHTML



For Example:



You defined a route called '/dynamic_html'



and it's component's template like this:



<div [innerHTML]="MY_HTML"></div>


You can link to this route by window.open('/dynamic_html') or any other solution.



Don't forget to sanitize your html.



happy coding !






share|improve this answer























  • excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

    – Nolik
    Nov 13 '18 at 9:33











  • No, What I mean is you can pass your html data in other new route that you can parse it in that component.

    – junk
    Nov 13 '18 at 9:41











  • actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

    – Nolik
    Nov 13 '18 at 11:15











  • i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

    – Nolik
    Nov 13 '18 at 19:47













2












2








2







First, you can beautify your template code wrapped by ``



and you don't need to add "n" any more



for Example:



`<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>`



Then let's fix your problem:



you can define some route and component to render the innerHTML



For Example:



You defined a route called '/dynamic_html'



and it's component's template like this:



<div [innerHTML]="MY_HTML"></div>


You can link to this route by window.open('/dynamic_html') or any other solution.



Don't forget to sanitize your html.



happy coding !






share|improve this answer













First, you can beautify your template code wrapped by ``



and you don't need to add "n" any more



for Example:



`<p class="error" (click)="this.openValidationWarningsInNewWindow(hello)">Validation Warnings - click to see details</p>`



Then let's fix your problem:



you can define some route and component to render the innerHTML



For Example:



You defined a route called '/dynamic_html'



and it's component's template like this:



<div [innerHTML]="MY_HTML"></div>


You can link to this route by window.open('/dynamic_html') or any other solution.



Don't forget to sanitize your html.



happy coding !







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 9:05









junkjunk

246418




246418












  • excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

    – Nolik
    Nov 13 '18 at 9:33











  • No, What I mean is you can pass your html data in other new route that you can parse it in that component.

    – junk
    Nov 13 '18 at 9:41











  • actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

    – Nolik
    Nov 13 '18 at 11:15











  • i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

    – Nolik
    Nov 13 '18 at 19:47

















  • excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

    – Nolik
    Nov 13 '18 at 9:33











  • No, What I mean is you can pass your html data in other new route that you can parse it in that component.

    – junk
    Nov 13 '18 at 9:41











  • actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

    – Nolik
    Nov 13 '18 at 11:15











  • i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

    – Nolik
    Nov 13 '18 at 19:47
















excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

– Nolik
Nov 13 '18 at 9:33





excuse me, but i didn't get your answer. Do u mean, that i'm able to use [innerHtml] for bounding and later put it into newWindow.document.write(innerHTML) ?>

– Nolik
Nov 13 '18 at 9:33













No, What I mean is you can pass your html data in other new route that you can parse it in that component.

– junk
Nov 13 '18 at 9:41





No, What I mean is you can pass your html data in other new route that you can parse it in that component.

– junk
Nov 13 '18 at 9:41













actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

– Nolik
Nov 13 '18 at 11:15





actually my aim, it's open simple html in new window, but before it, i need to build this html (from template with buinding). how i understood u propose to create separate component tat will be open in new window through routerLink - but in this case i need to transfer input data into this component. Possible i mess your idea, could u simplify demonstrate it in plunker ?>

– Nolik
Nov 13 '18 at 11:15













i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

– Nolik
Nov 13 '18 at 19:47





i read more about [innerHTML] and it's not my case, coz "MY_HTML" will be the same string, that i able directly past into the newWindow.document.write(MY_HTML) and open it in separate tab.

– Nolik
Nov 13 '18 at 19:47

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277093%2fangular-6-need-to-open-new-tab-from-componenent-with-new-builded-html-included%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto