CSS格式未缩进ng-repeat输出的第二行

时间:2018-09-10 21:35:45

标签: html css angularjs

尝试从脚本获取以下格式的输出: 营业天数:

                Sunday:     Closed
                Monday:     8am - 9am
                            9am - 10am
                Tuesday:    8am - 9am
                            9am - 12pm
                Wednesday:  8am - 9am
                Thursday:   9am - 10am
                            11am - 12pm

…等。相反,输出最终如下所示:

Days of operation:  
                    Sunday:     Closed 
                    Monday:     8am - 9am  
                    9am - 10am
                    Tuesday:    8am - 9am
                    9am - 12pm
                    Wednesday:  8am - 9am
                    Thursday:   9am - 10am
                    11am - 12pm

可以使用一些帮助来弄清楚我对布局图所做的错误操作,这使我无法获得所需的结果。这是我在index.css中用于格式化的代码:

#details label{
  width: 240px;
}
#details .hours-layout{
    float: left;
    width: 100px
}
.label-left {
  float: left;
}
.content-right {
  display: block;
  overflow: hidden;
}

这是我的html脚本中的代码:

<div role="tabpanel" class="tab-pane fade" id="details">
                    <div class="content">
                      <div><label class="label-left">{{listing_ctrl.COMMON.facilityType}}:</label><span class="content-right">{{ listing_ctrl.listing.program }}</span></div>
                      <div><label class="label-left">{{listing_ctrl.COMMON.facilityOpened}}:</label><span class="content-right">{{ listing_ctrl.listing.dateFounded ? (listing_ctrl.listing.dateFounded | date:'MM/dd/yyyy':'+0') : "Not Available" }}</span></div>
                      <div><label class="label-left">{{listing_ctrl.COMMON.capacity}}:</label><span class="content-right">{{ listing_ctrl.listing.capacity }}</span></div>
<!--New lines v2-->
                      <div ng-switch="listing.rawData.opHoursAvailable">
                            <div ng-switch-when = "N"><label class="label-lelft">{{listing_ctrl.COMMON.hoursOfOp}}:</label><class="content-right">Not available</div>
                            <div ng-switch-default>
                                <p><label class="label-left">{{listing_ctrl.COMMON.hoursOfOp}}:</label><span class="content-right">
                                        <span ng-if="listing_ctrl.listing.operatingHours">
                                            <span ng-repeat="day in listing.operatingHours">
                                                <span class="hours-layout">{{day.day}}:</span>
                                                    <span ng-repeat="sched in day.sched">
                                                        <span ng-switch = "sched.open">
                                                            <span ng-switch-when = "">
                                                                Closed <br/>
                                                            </span>
                                                            <span ng-switch-default class="hours-layout2">
                                                                {{sched.open}} - {{sched.close}}<br/>
                                                            </span>
                                                        </span>
                                                    </span>
                                                </span>
                                            </span>
                                        </span>
                                </p>
                            </div>
                        </div>

2 个答案:

答案 0 :(得分:1)

您可以在style属性中使用插值法来设置ng-repeat中第二(以及第三,第四...)项的边距。将评论和答案拼凑在一起,这是您的可行解决方案。您必须使用<div>而不是<span>的原因是<span>标签不能使用边距或高度style设置。就个人而言,我总是更喜欢使用<div>元素进行定位。我通常只将<span>ng-if一起使用来显示条件文本或将字体/文本样式应用于较长文本字符串中的一个或两个单词。

<div ng-repeat="sched in day.sched">
   <div ng-switch = "sched.open">
          <div ng-switch-when = "">
                Closed
          </div>
          <div ng-switch-default style="{{ $index > 0 ? 'margin-left : 100 px' : '' }}">
               {{sched.open}} - {{sched.close}}
          </div>
    </div>
</div>

我问有关Bootstrap的原因是因为当您使用布局框架时,它变得更干净了。 Bootsrap(和Material)使用行/列类型的布局,这使您轻松实现所追求的目标和响应。当您需要抵消时间时,只需使用offset添加一个ng-class类。就我个人而言,我发现这种方法比在style属性中使用插值更为简洁。

<div class="row" ng-repeat="sched in day.sched">
   <div ng-switch = "sched.open">
          <div class="col-xs-6" ng-switch-when = "">
                Closed
          </div>
          <div class="col-xs-6" ng-switch-default ng-class="{'col-xs-offset-6': $index > 0}">
               {{sched.open}} - {{sched.close}}
          </div>
    </div>
</div>

答案 1 :(得分:0)

类似以下内容应该会对您有所帮助。

<span ng-repeat="sched in day.sched">
   <span ng-switch = "sched.open">
          <span ng-switch-when = "">
                Closed <br/>
          </span>
          <span ng-switch-default class="hours-layout2" ng-style="$index > 1 && margin-left : 100 px">
               {{sched.open}} - {{sched.close}}<br/>
          </span>
    </span>
</span>

说明:您可以使用ng-style实现条件格式。更多信息here