警报消息上的新行

New line on alert message

在 Ionic 3 中是否可以使用警报显示新行?

我应该用什么替换'\n'?

doFinalise() {
let confirm = this.alertCtrl.create({
  title: 'Are you sure?',
  message: 'Are these details correct?\n Price ($/L): \n KMs Done: \n Total Spent: \n Fuel Type: \n Date: ',
  buttons: [ etc...

最终,消息将在新行之前显示变量,但现阶段不需要。

AlertController 可以解析 HTML 标签。所以你可以在这里使用 <br/> 标签。

let confirm = this.alertCtrl.create({
  title: `Are you sure?`,
  message: `Are these details correct?<br/> Price ($/L): <br/> KMs Done: <br\> Total Spent: <br\> Fuel Type: <br\> Date: `,
  buttons: [ etc...

或者您可以查看 my demo 并尝试使用项目符号或编号。

let alert = this.alertCtrl.create({
      title: 'Are you sure?',
      message: `
        Are these details correct?
        <ul>
          <li>Price ($/L):</li>
          <li> KMs Done: </li>
          <li>Total Spent: </li>
          <li>Fuel Type:</li>
          <li> Date: </li>
        </ul>
      `,

来源:this forum post 作者 Mike Hartington of Ionic

是的,离子弹出内容中可以有换行符。

将 \n 替换为 < br > 标签即可。离子框架在执行 javascript 后输出 HTML。