【问题标题】:Right aligning columns given conditions in Angular 2 / Ionic 2在Angular 2 / Ionic 2中给定条件右对齐列
【发布时间】:2018-05-03 07:14:01
【问题描述】:

我想通过应用justify-content-endtext-right 来选择性地右对齐某些列,当它们与每条记录的某些条件匹配时,使得呈现的版本看起来像这样:

<ion-content padding>

  <ion-grid>
    <ion-row>
      <ion-col col-8>Stuff</ion-col>
    </ion-row>
    <ion-row justify-content-end text-right>
      <ion-col col-8>Stuff 2</ion-col>
    </ion-row>
    <ion-row>
      <ion-col col-8>Stuff 3</ion-col>
    </ion-row>
    <ion-row justify-content-end text-right>
      <ion-col col-8>Stuff 4</ion-col>
    </ion-row>
  </ion-grid>

</ion-content>

如何将其放入代码中?我需要以某种方式使用*ngIf吗?

【问题讨论】:

    标签: css angular ionic-framework ionic2


    【解决方案1】:

    不需要*ngIf,只需要ngClass

    <ion-row [ngClass]="{'justify-content-end': true, 'text-right': false }">...</ion-row>
    
    // OR : If both classes have same conditions
    
    <ion-row [ngClass]="{'justify-content-end text-right' : true}">...</ion-row>
    

    用你的conditions代替true / false

    更多详情请阅读:NgClass


    对于动态属性使用,

    [attr.justify-content-end]='true/false'
    

    【讨论】:

    • 这似乎将justify-content-endtext-right 添加到类中,但我需要将它们作为属性添加到&lt;ion-row&gt;,使其看起来像:&lt;ion-row justify-content-end text-right&gt;
    • 然后使用 [attr.justify-content-end]='true/false'
    • 这个是赢家!谢谢你:)
    【解决方案2】:

    你可以使用这样的东西

    当真时:

    <ion-row justify-content-end text-right *ngIf="msg.mycondition">
      <ion-col col-8>Stuff 2</ion-col>
    </ion-row>
    <ion-row *ngIf="!msg.mycondition">
      <ion-col col-8>Stuff 2</ion-col>
    </ion-row>
    

    【讨论】:

    • 当每个离子行是:&lt;ion-row *ngFor="let msg of messages" [...]&gt;Stuff&lt;/ion-row&gt;时,这将如何工作?
    • Vivek Doshi 的 [attr.justify-content-end]='true/false' 评论做到了,谢谢您的意见!
    猜你喜欢
    • 2017-11-28
    • 2016-06-26
    • 2017-12-30
    • 2018-03-15
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多