0

I have an input and a table:-

<label>Label1:</label>
   <input type="text" ng-model="a.value" ng-change ="filterArray(a.value)"/>

<table cellpadding="0" cellspacing="0">
      <thead>
            <tr>
                <th>Branch Code</th>
            </tr>
      </thead>
      <tbody>
            <tr ng-repeat="row in arr track by $index">
                <td>{{row}}</td>
            </tr>
      </tbody>
 </table>

I have an array:- a. arr = [11, 1001, 4300, AA61, 1234, B675]

What I want is when user input 1 then a.arr becomes [11, 1001, AA61, 1234] and it shows in table.

How to achieve this?

5
  • You can use ng-if to check if your variable {{row}} contains the input Commented Oct 12, 2017 at 11:45
  • You can also see this link for filters docs.angularjs.org/api/ng/filter/filter Commented Oct 12, 2017 at 12:17
  • did the answer help you? Commented Oct 13, 2017 at 10:19
  • @Sajeetharan, yes thanks Commented Oct 16, 2017 at 6:32
  • @shreyagupta please mark as answer Commented Oct 16, 2017 at 6:32

1 Answer 1

4

You do not need ng-change here, you can directly use filter,

DEMO

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
   $scope.arr = ['11', '1001', '4300', 'AA61', '1234','B675'];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<label>Label1:</label>
   <input type="text" ng-model="value" />

<table cellpadding="0" cellspacing="0">
      <thead>
            <tr>
                <th>Branch Code</th>
            </tr>
      </thead>
      <tbody>
            <tr ng-repeat="row in arr  | filter:value">
                <td>{{row}}</td>
            </tr>
      </tbody>
 </table>
 </body>

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.