0

I have this Schema in mongoDB:

var CostSchema = new Schema({
    item: String,
    value: Number
});

var AttachmentsSchema = new Schema({
    item: String,
    url: String
})

var ServiceSchema = new Schema({
    item: String, // maybe another Schema [] to be able to search for this criteria
    description:String,
    worker: { type: Schema.Types.ObjectId, ref:'Worker'}, //Saves Worker ID 
    date_assigned: Date,
    price:Number
});

var JobsSchema = new Schema({ 
    manager: { type: Schema.Types.ObjectId, ref:'Admin', required:true}, // Saves Manager Name       
    propertie: { type: Schema.Types.ObjectId, ref: 'Propertie', required:true}, //Saves Property Name 
    unit: String,
    completed: Boolean,
    costs: [CostSchema],
    services:[ServiceSchema], 
    totalPrice: Number,
    totalCost:Number,
    poNumber: { type : String, unique: true, sparse:true },
    invoiceNumber: { type : String, unique: true, sparse:true },
    notes: String,
    date_completed: Date,
    attachments: [AttachmentsSchema],
    notification_sent: Boolean
});

So depending on the Job it will have a completed date or not i am trying to apply the following filter in the front-end

<div class="page-header col-xs-12">
  <h3 class ='text-center'>Pending Jobs</h3> 
  <div class="form-group col-xs-8 col-xs-offset-2 text-center">
    <label for="searchJobBox1">Filter</label>
    <input ng-model = 'job.$' type="text" class="form-control" id="searchJobBox1" placeholder="Quick Filter...">
  </div>
  <div class="form-group col-xs-2 col-xs-offset-3 text-center">
    <label for="jobPropertyFilter" class="col-xs-2 control-label">Property</label>
    <div>
      <select ng-model = 'job.propertie._id' class="form-control" id='jobPropertyFilter'>
        <option></option>
        <option  value = '{{property._id}}' ng-repeat ='property in properties'>
        {{property.name}}
        </option>
      </select>
    </div>
  </div>
  <div class="form-group col-xs-2 text-center">
    <label for="jobWorkerFilter" class="col-xs-2 control-label">Worker</label>
    <div>
      <select ng-model = 'job.services.worker._id' class="form-control" id='jobWorkerFilter'>
        <option></option>
        <option  value = '{{worker._id}}' ng-repeat ='worker in workers'>
        {{worker.first}} {{worker.last}}
        </option>
      </select>
    </div>
  </div>
  <div class="form-group col-xs-2 text-center">
    <label for="jobManagerFilter" class="col-xs-2 control-label">Manager</label>
    <div>
      <select ng-model = 'job.manager._id' class="form-control" id='jobManagerFilter'>
        <option></option>
        <option  value = '{{admin._id}}' ng-repeat ='admin in admins'>
        {{admin.first}} {{admin.last}}
        </option>
      </select>
    </div>
  </div>
</div>

I have two ng-repeats in place as follows: 1) Is Working Perfectly

<div class="panel panel-default" ng-repeat = 'job in jobs| filter:job:strict' ng-if='!job.date_completed' >

2)

 <div class="panel panel-default" ng-repeat = 'job in jobs| filter:job:strict' ng-if='job.date_completed' >

For some reason that i haven't been able to figure out, Angular will apply the filter to every job with a date_completed property and they are not being displayed it does not have anything to do with the ng-if, which is working just fine.

Any advice?

1
  • It's a little unclear exactly what you'd like to do here. Are you trying to get these to filter independently? Or is one not filtering while the other is? Commented Jul 1, 2016 at 23:06

1 Answer 1

1

On your second example ng-if would display the element only if job.date_completed is defined.

I can only asume that job.date_completed is *undefined*.

Try to use console.log for printing the value of job.date_completed

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

Comments

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.