0

I have this schema for business_hours:

 business_hours: {
        sunday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        monday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        tuesday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        wednesday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        thursday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        friday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]},
        saturday: {closed: {type:Boolean, trim: true},
            timings: [{
                open: {type:Number, default: '', trim: true},
                close: {type:Number, default: '', trim: true}
            }]}
    },

I am creating UI for above schema. So I am using ng-repeat for this purpose. I have defined an array week in my controller:

 $scope.week = ['Sunday','Monday' ,'Tuesday' ,'Wednesday' ,'Thursday' ,'Friday', 'Saturday'];

And HTML code is as follows:

<div class="row-fluid span12">
            <small>Timings</small>
        </div>
        <div ng-repeat="w in week">

        <div class="row-fluid pushTop10px">
            <div class="row-fluid span4">
                <small>{{w}}</small>
            </div>
            <div class="row-fluid span8 " >
                <div class="row-fluid span2" style="text-align:center; margin-top:4px;">
                    <small>Open</small>
                </div>
                <div class="row-fluid span2">             
                    <select class="span12" ng-model="outlet.business_hours.timings.w.open.hour">
                    <option value="1"><label>00</label></option>
                    <option value="2"><label>01</label></option>

This code goes on. Basically there are four things: open hour, open minute, close hour, close minute. w in week is working when I am simply printing it. But when I am using it in model, it doesn't work. I have also tried following code:

outlet.business_hours.timings.{{w}}.open.hour
outlet.business_hours.timings.week[w].open.hour
outlet.business_hours.timings.week($index).open.hour

How can it be done?

1

2 Answers 2

1

Could you try

outlet.business_hours[w].timings[0].open(hour)

Where hour is a property in scope

Additionaly, Sunday != sunday ;)

Could you provide more code?

Sign up to request clarification or add additional context in comments.

Comments

0

Here's how:

 outlet.business_hours[w].timings[0].open.hour

5 Comments

Not working. Error is "Cannot read property 'open' of undefined"
Are you sure 'open' is defined? What does {{ outlet.business_hours['sunday'] }} output?
Have you made changes suggested by @ysf?
name of the day in variable w is capitalized. however, name of days in business_hours are lowercase. since javascript is case-sensitive business_hours['sunday'] is different than business_hours['Sunday']. either make $scope.week values lowercase or capitalize property names of business_hours object.
Also, where does hour come from? It's not defined in your schema?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.