2017-10-05 56 views
0

我正在使用PrimeNg Collection的ConfirmDialog組件。我可以將我的消息,因爲這:從模板設置PrimeNG確認消息

this.confirmationService.confirm({ 
     message: 'my message', 
    }); 

它的工作原理,但問題是,它就會變得混亂,如果我需要一個大的集合與在那裏的其他組件的標籤。我想在HTML模板中編寫我的消息,並在其中嵌入Angular的指令和組件,並在p-confirmDialog標籤中。

我該如何做到這一點?

+0

https://stackoverflow.com/a/45789799/8468804也許在這篇文章中實現類似於我的答案的解決方法。介意你,但如果你想實現一個變量/財產模板將是混亂的任何方式。 –

+0

我不想黑客和解決方法。如果Angular如此偉大,那麼一切都應該有可能以正確的方式進行。 – Gherman

回答

0

這是另一種方法,我認爲這是一個更合適的方法來做到這一點。

HTML

<p-confirmDialog appendTo="body"> 
<ng-template pTemplate="body"> 
    <span class="ui-confirmdialog-message">{{message}}</span>" 
</ng-template> 

TS

... 
constructor(private confirmationService: ConfirmationService) {} 

private message = `Do you want to change your status to <span style="color:red">inactive</span>` //your template html; 
... 
this.confirmationService.confirm({ 
    header: "Some header", 
    message: this.message, 
    accept:() => { 
    //Do something 
    } 
}); 

你總是可以有一個專門的服務調用ConfirmationService並傳入message如你所願。