2017-04-25 68 views
0

離子打印機插件使用Printer.print([html string],[打印機選項])功能使用移動應用程序打印出來。創建打印模板頁面 - 離子2

我需要創建html模板並動態更新一些值並使用模板作爲打印功能的輸入。

任何人都可以有任何想法如何做到這一點?

我正在使用ionic 2和android平臺。

+0

你到底需要什麼?要知道如何打印?要知道如何獲得打印的HTML?如何擁有動態字段並打印呢?你嘗試過什麼嗎?你可以分享你的代碼嗎? –

+0

我想知道如何獲得打印的html。我想從單獨的文件中得到這個HTML不在我的打字稿文件中。而且還需要有動態的領域。 – Sachintha

回答

0

這取決於究竟想要打印什麼。

我可能會在代碼中創建一個HTML模板,然後在打印之前替換這些值。

例子:

class Page { 

    template: string = `<h1>{title}</h1> 
     <p>This is a paragraph</p> 
     <p>{content}</p>`; 

    getHTML(title, content) { 
     let str = template; 
     str = str.replace('{title}', title); 
     str = str.replace('{content}', content); 
     return str; 
    } 

    printPage(title, content) { 
     let options = {}; 
     this.p.print(getHTML(title, content), options).then(onSuccess, onError); 
    } 

}