1

I am trying to apply the filters on the ng-repeat based on user selection in section options.But unable to do that so far.
Update-It works !! Here's Plunker

HTML

  <div class="container">
  <div ng-include="" src="'refiners.html'"></div>
  <br />
  <br />
  <div class="row">
 <div class="col-xs-12">
      <ul>
        <li ng-repeat="item in data.Results | filter:cc">
          <div>
            <p>{{item.Title}}</p>
            <p>{{item.City}}</p>
            <p>{{item.PostalCode}}</p>
            <span>{{item.MinimumSalePrice | currency}}</span>
            <span>{{item.MaximumSalePrice |currency}}</span>
            <p>{{item.PropertyType}}</p>
            <p>{{item.TenureType}}</p>
          </div>
        </li>
      </ul>
    </div>
sts
  • 43
  • 4
  • Can you include the code for the cc filter? I realize it's probably in the plunker, but you probably don't want to create extra work for people who may answer your question. – tandrewnichols Apr 20 '15 at 01:33
  • i don't have any cc filter . I was trying to do as in http://jsfiddle.net/MLps6/110/ – sts Apr 20 '15 at 01:38
  • Oh, so you're trying to write a filter. That's not totally clear from your question. Also not clear from your question: what should said filter do? – tandrewnichols Apr 20 '15 at 01:42
  • its JSON format. If you see Plunker its there. Based on user selection data should be shown. like if user selected city-Paris.Then data which has city "Paris" should be shown only. – sts Apr 20 '15 at 01:44
  • Wow, I really misunderstood what you were trying to do. Think I'm on the same page now. You probably want Till Weiss's answer; that seems like the likely solution. – tandrewnichols Apr 20 '15 at 01:48

1 Answers1

1

When you do ng-include you create a new scope so cc is always empty in the parent scope.

This is similar to the issue in this in question. AngularJS - losing scope when using ng-include

You can fix it by adding $scope.cc={} to your controller (creating this element in the parent $scope so the filter has access to it. For this to work you will have to remove the ng-init calls from refiners.html, since these will create a new object in the child scope.

Community
  • 1
  • 1
Till Weiss
  • 51
  • 3
  • Great! Thanks.It works but then how to clear the filter when user selects All form options ? – sts Apr 20 '15 at 02:16