【问题标题】:Printing Array on Html with Angular使用 Angular 在 Html 上打印数组
【发布时间】:2019-03-12 15:33:49
【问题描述】:

我是第一次使用 Angular,我正在尝试显示一些数据。数据在一个数组中

[我,三,四]

我正在尝试循环打印数据,但它不起作用。目前,我正在这样做

    <ng-container matColumnDef="channel">
        <th mat-header-cell *matHeaderCellDef> Channel </th>
        <td mat-cell *matCellDef="let element"> {{element.channel}} </td>
    </ng-container>

我在专栏上得到的是这个

[我,三,四]

channel: "[ME, WE, US]"
end: "2018-03-29T08:00:00Z"
states: "[NY, Non-NY]"
start: "2018-03-29T08:00:00Z"
trans: "[Act:Add]"

如何从数据中删除 []?谢谢

【问题讨论】:

    标签: angular html angular7


    【解决方案1】:

    试试这样的:

     <ng-container matColumnDef="channel">
        <th mat-header-cell *matHeaderCellDef> Channel </th>
        <td mat-cell *ngFor="let element of nameOfArray"> {{element}}</td>
     </ng-container>
    

    【讨论】:

      【解决方案2】:

      如果你的数组/json 是这样的

      channel: "[ME, WE, US]"
      end: "2018-03-29T08:00:00Z"
      states: "[NY, Non-NY]"
      start: "2018-03-29T08:00:00Z"
      trans: "[Act:Add]"
      

      比添加html

       <ng-container *ngFor="let element of nameOfArray">
                  <th mat-header-cell> Channel </th> 
                  <th mat-header-cell> end</th>
                  <th mat-header-cell> states</th>
                  <th mat-header-cell> start</th>
                  <th mat-header-cell> trans</th>
                <td mat-cell >{{element.channel}}</td>
                <td mat-cell >{{element.end}}</td>
                <td mat-cell >{{element.states}}</td>
                <td mat-cell >{{element.start}}</td>
                <td mat-cell >{{element.trans}}</td>
       </ng-container>
      

      如果你想删除它

      end: "2018-03-29T08:00:00Z"
      

      比您休息时无法获得(访问) 或者不能在你的 html 中重写从上面的代码中删除。

      【讨论】:

        猜你喜欢
        • 2017-10-05
        • 2020-05-27
        • 1970-01-01
        • 2016-04-12
        • 2012-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多