1

Lets say i want to print a variable that i create dinamicly with HTML syntax. In my HTML i want to print the new HTML but i dont know how.

If i print the variable in the HTML, it would print it like a Text.

This is the HTML i want to print:

this.content = this.elementRef.nativeElement.querySelectorAll('sys-tab-content');

but if i print this:

<div>
  {{content[0]}}
</div>

it would just print the text and not like a HTML

EDIT I just want to print this object inside my HTML, excatly as it is.. but When i print it, it just prints what i told you: [object HTMLElement]

Is there a way for me to print this Elements, i know it is not HTML but components.

iConsole log

Hely Saul Oberto
  • 577
  • 1
  • 10
  • 22

1 Answers1

2

You probably want one of

{{content && content[0].innerText}}
{{content && content[0].innerHTML}}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • When i console.log content[0] has exactly what i want to print and when i put the innertext or innerhtml it doesnt print everything – Hely Saul Oberto Sep 19 '17 at 12:30
  • 1
    It depends on where your code is. Check if you get an error in the browser console. I updated my answer so that it doesn't cause an error when `content` is not yet set. If you have the code in the constructor, move it to `ngAfterViewInit()` – Günter Zöchbauer Sep 19 '17 at 12:32
  • content is set. When i print content[0] it prints [object HTMLElement]... I change the printing as you told me but it stil prints all the HTML but as text – Hely Saul Oberto Sep 19 '17 at 12:38
  • https://stackoverflow.com/questions/31548311/angular-2-html-binding/41089093#41089093 – yurzui Sep 19 '17 at 12:49
  • @yurzui that might be. I interpreted it so that he wants to get the text. As long as he doesn't bind to `innerHTML` I think it should add the content as text. Because it's quite unclear what the content is that he expects it's diffcult to tell. – Günter Zöchbauer Sep 19 '17 at 12:52
  • @HelySaulOberto I don't see a way to provide support with the provided information. It's entirely unclear what the problem is and what behavior you expect. I think this requires at least a clear example to reproduce in Plunker or similar to investigate. – Günter Zöchbauer Sep 19 '17 at 12:52
  • 1
    Lately there are a lot of strange questions. So i agree that it's hard to predict what he had in mind – yurzui Sep 19 '17 at 12:57
  • @HelySaulOberto that doesn't really help. – Günter Zöchbauer Sep 19 '17 at 13:01