如何在ui.bootstrap模式对话框的bodyText中格式化(新行)

时间:2016-03-26 18:51:21

标签: javascript angularjs showmodaldialog ui.bootstrap

我的AngularJS脚本中有一个ui.bootstrap confirmdlg:

var modalDlgOptions = {
  closeButtonText: "No",
  actionButtonText: "Yes",
  headerText: "my header text",
  bodyText: "my body text" 
};
confirmDlg.showModal({}, modalDlgOptions).then(function (result) {
  // todo something         
});     

这很好用。但现在我想格式化bodyText。我需要这样的新行:

first line in my body text
second line in my body text
...
last line in my body text

当我使用

bodyText: "first line in my body text<br>second line in my body text<br>...<br>last line in my body text";

bodyText: "first line in my body text&lt;br&gt;second line in my body text&lt;br&gt;...&lt;br&gt;last line in my body text";

我得到了

first line in my body text&lt;br&gt;second line in my body text&lt;br&gt;...&lt;br&gt;last line in my body text

在我的对话框输出中,但不是新行

是否可以格式化confirmDlg的bodyText以及如何?

感谢您的提示,Thomas

2 个答案:

答案 0 :(得分:0)

我找到了这个解决方案:

var modalDlgOptions = {
  closeButtonText: "No",
  actionButtonText: "Yes",
  headerText: "my header text",
  bodyText: "" 
};

confirmDlg.showModal({}, modalDlgOptions).then(function (result) {
  // todo something         
}); 

setTimeout(function() { 
  var modalBody = document.getElementsByClassName("modal-body");
  modalBody[0].innerHTML = "first line in my body text<br />second line in my body text<br /> ... <br />last line in my body text";
}, 100);    

感谢评论,托马斯

答案 1 :(得分:0)

改进以前的解决方案:

var waitForElementByClassName  = function(element, timeout, callBack) {
      window.setTimeout(function(){
        if (document.getElementsByClassName(element)[0]){
          callBack(document.getElementsByClassName(element)[0]);
        } else {
            waitForElementByClassName(element, timeout, callBack);
        }
      }, timeout);
};

waitForElementByClassName("modal-body", 50, function(element) {
        element.innerHTML = "first line in my body text<br />second line in my body text<br /> ... <br />last line in my body text";
        });