Reputation: 455
Trying to obtain the following format for output from script: Days of operation:
Sunday: Closed
Monday: 8am - 9am
9am - 10am
Tuesday: 8am - 9am
9am - 12pm
Wednesday: 8am - 9am
Thursday: 9am - 10am
11am - 12pm
… and so on. Instead, output ends up like this:
Days of operation:
Sunday: Closed
Monday: 8am - 9am
9am - 10am
Tuesday: 8am - 9am
9am - 12pm
Wednesday: 8am - 9am
Thursday: 9am - 10am
11am - 12pm
Could use some help to figure out what I'm doing incorrectly with the layout piece that's preventing me from getting the desired result. Here's the code I have in my index.css for formatting:
#details label{
width: 240px;
}
#details .hours-layout{
float: left;
width: 100px
}
.label-left {
float: left;
}
.content-right {
display: block;
overflow: hidden;
}
Here's the code from my html script:
<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>
Upvotes: 0
Views: 97
Reputation: 7194
You can use interpolation within the style
attribute to set your margin on the second (and third, fourth...) items in your ng-repeat
. Putting the pieces together from the comments and answers here is your working solution. The reason you have to use a <div>
instead of a <span>
is that <span>
tags cannot use margin or height style
settings. Personally, I always prefer to use <div>
elements for positioning. I typically only use <span>
along with ng-if
to display conditional text or to apply font/text styles to a word or two in a longer string of text.
<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>
The reason I asked about Bootstrap is because this becomes a little cleaner when you use a layout framework. Bootsrap (and Material) use row/column type layouts which makes achieving what you're after easier and responsive. When you need to offset your hours you simply add an offset
class using ng-class
. Personally, I find this approach much cleaner than using interpolation within the style
attribute.
<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>
Upvotes: 1
Reputation: 1392
some thing like the following should help you.
<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>
Explaination : you can achieve conditional formatting using ng-style. More info here
Upvotes: 0