0

I'm developing hotel booking site. I have completed development on load data from WebAPI. I want to add filters after page load.

Script

function getAll() {
    var sub = {
        Des: $scope.Des,
        DepartureDate: $scope.DepartureDate,
        ReturnDate: $scope.ReturnDate,
        Rooms: $scope.Rooms,
     };

    var getAll = APIService.hotelavailability(sub);
    getAll.then(function (d) {
        console.log("Succss");
        $scope.respData = d.data.hotels;
    }, function (error) {
        console.log('Oops! Something went wrong.');
}

CHTML Code

<div class="hotel_filter">
 <input ng-model="hotelName" class="form-control" placeholder="Search hotel" type="text" id="searchbox">
</div>
<div ng-repeat="hotel in respData.hotels" class="clearfix">  
 <h2>{{hotel.name}}</h2>
</div>

How can i filter hotel data after page load from input box(searchbox)?.

Thusitha Indunil
  • 832
  • 1
  • 8
  • 22
sanjeewa
  • 564
  • 1
  • 5
  • 17

1 Answers1

1

Have a look at this. It is exactly what you describe. https://docs.angularjs.org/api/ng/filter/filter . Examples are shown there, but here you go :

<div class="hotel_filter">
 <input ng-model="hotelName" class="form-control" placeholder="Search hotel" type="text" id="searchbox">
</div>
<div ng-repeat="hotel in respData.hotels | filter:hotelName" class="clearfix">  
 <h2>{{hotel.name}}</h2>
</div>
Dinca Adrian
  • 1,190
  • 11
  • 21
  • thanks. its work . how can i filter particulate fields on hotel object? – sanjeewa Jun 23 '17 at 05:46
  • the inputs should have the same model defined as the fields you want to search for. also in that documentation there is a search by field only. The bottom of the page – Dinca Adrian Jun 23 '17 at 09:31