简体   繁体   English

如何在 textarea 中格式化或设置文本样式?

[英]How to format or style text in textarea?

I need to create a textarea to display data, it should looks like this(expected behavior):我需要创建一个 textarea 来显示数据,它应该是这样的(预期行为):

在此处输入图片说明

This is my current UI (current behavior):这是我当前的用户界面(当前行为):

在此处输入图片说明

This is my HTML:这是我的 HTML:

<textarea disabled class="bgYellow" rows="6">{{text1}}</textarea>

This is my Typescript Code:这是我的打字稿代码:

  invoiceNo = '1000799758-00';
  status = 'Spark';
  palletLP = '';
  needAudit = 'NO';

  text1 = 'Invoice No.:  ' + this.invoiceNo + '\n' +
          'Status:  ' + this.status + '\n' +
          'Pallet LP:  ' + this.palletLP + '\n' +
          'Audit?:  ' + this.needAudit;

Can any one tell me how Can I make this Invoice No. Label align to left, data align to right.谁能告诉我如何让这个发票编号标签左对齐,数据右对齐。 It is like Bootstrap grid style, but I am not sure how to do it.它就像 Bootstrap 网格样式,但我不知道该怎么做。

Use the single backtick :使用单个反引号:

 text1 = `
Invoice No, : 1
Status      : 2
Pallet LP   : 3
...         : 4`
}

https://stackblitz.com/edit/angular-aewrtv?file=src/app/app.component.ts https://stackblitz.com/edit/angular-aewrtv?file=src/app/app.component.ts

change your code into将您的代码更改为

text1 =  ' Invoice No.: ' + this.invoiceNo + '\n' +
      '      Status: ' + this.status + '\n' +
      '   Pallet LP: ' + this.palletLP + '\n' +
      '      Audit?: ' + this.needAudit;

And then change the text area to use a terminal (fixed width font) using css will hopefully fix the problem.然后使用css更改文本区域以使用终端(固定宽度字体)有望解决问题。

Changing The Font Of Text Area 更改文本区域的字体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM