0

If item matches the Array element filter the result have the below json structure

  [{"id": "1", "name":"product1","items": ["item1","item2"],},
  {"id": "2", "name":"product2","items": ["item4","item3"],},
  {"id": "3", "name":"product3","items": ["item5","item1"],}]

Requirement is if i select item1 from drop down i need to filter the entire object which contains item1. I am new to angular js can any one help me out

2 Answers 2

1

Use filter in ng-repeat

via text-box

Search by item: <input type="text" ng-model="search.items">
<div ng-repeat="product in data | filter:search">
  {{product}}
</div>

via drop-down

<select class="form-control" ng-model="selectedThana" ng-options="t.items for t in data">
    <option value="">Select</option>
</select>
<div ng-repeat="product in data | filter:selectedThana">
  {{product}}
</div>

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
   $scope.data = [{"id": "1", "name":"product1","items": ["item1","item2"],},
  {"id": "2", "name":"product2","items": ["item4","item3"],},
  {"id": "3", "name":"product3","items": ["item5","item1"],}];
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
  <select class="form-control" ng-model="selectedThana" ng-options="t.items for t in data">
                        <option value="">Select</option>
                    </select>
<div ng-repeat="product in data | filter:selectedThana">
  {{product}}
</div>
</body>

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

2 Comments

Thanks. in drop down i will have item1,itme2,itm3 if select item one
{"id":"1","name":"product1","items":["item1","item2"]} {"id":"3","name":"product3","items":["item5","item1"]} these two arrys should get selected
0

You can do this using $filter,

HTML

<select ng-model="user" ng-change="getselected(user)" ng-options="code.name as code.name for code in optionsdownload">
</select>

Controller

 $scope.getselected = function(item){
    $scope.wholeobj = $filter("filter")($scope.optionsdownload, item);
 }

DEMO

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.