Document.getElementById no Ionic

Asked

Viewed 274 times

0

I have an application developed with Ionic 3 and would like to know if this type of implementation should work. I have an html file with a div with id = corpoId. And in the implementation I open the file and try to write in this div:

const windowPrint = window.open('/android_asset/www/catalogo.html', '_blank');
var textoHtml = '<html>apenas exemplo de html</html>'
windowPrint.document.getElementById('corpoId').innerHTML = textoHtml;

  • You should tell us if the implementation worked! It worked, no error in the console?

  • did not work, did not give error in the console. html file opens, but without writing done in body.

  • The way it is there, you’re getting an id of a method open window.(), it would be right to take an id of an Html page, create a variable and place the example page path: var url = /android_asset/www/catalogo.html, then you do window.open(url) and then makes url.getElementById('corpoId'). innerHTML = textoHtml

  • url.getElementById('body'). innerHTML

  • Why not? Error, which?

  • nor compile friend, [ts] Property 'getElementById' does not exist on type 'string'.

  • But you’re putting it into some function?

  • I am inside a method where I assemble html tags and play in a string variable and then call those lines I mentioned that do respectively (or should do): open the file and write to div

  • Put all that code there friend, because this error is of ts has no relation to what I exemplified!

  • there’s no way to work what you exemplified, you don’t have this getElementById property in url, so don’t even compile....

  • Our guy, forget it. There’s really no way to work what I did, I’m in the company and working with Ionic tbm and mixed the question with the job here.

  • Man from what I read here in the method open window.() I don’t think you can write in a specific element, only directly in the document type Document.write(<p>Content here</p>).

  • thanks for trying to help, I was able to solve: const tela_impressao = window.open('/android_asset/www/catalogo.html', '_Blank'); var textoHtml = '<div></div>' tela_impressao.document.write(textoHtml); tela_impressao.window.print(); tela_impressao.window.close();

  • Put there as an answer to help other users.

  • I posted in the comment above, it wasn’t quite what I needed, but I don’t know if it has to do otherwise.

Show 10 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.