Nicoleta Wilskon Nicoleta Wilskon - 1 month ago 4
AngularJS Question

Using ng-model in search filter

I have a search filter in table and I given ng-model name as selectedGcode for it. I am calling ng-click =viewAccount() inorder to call the function on click. But I am getting $scope.selectedGcode in my controller as undefined.


<table class="table table-striped">
<tr class="myheading">
<th class="col-sm-2"> Code
<th class="col-sm-2">Name

<th class="col-sm-2" >
<input type="text" class="form-control" ng-model="selectedGcode" placeholder="Search" ng-click="viewAccount()" /></th>
<th class="col-sm-2" >
<input type="text" class="form-control" /></th>

<tr data-ng-repeat="data in tableData">
<td class ="stylethecontent" >{{ data.groupzcode}}</td>
<td class ="stylethecontent" >{{data.groupzname}}</td>


$scope.viewAccount = function(){

var json = {

"json": {
"request": {
"servicetype": "6",
"functiontype": "6014",
"session_id": $rootScope.currentSession,
"data": {
"shortname": $scope.selectShortName,


UserService.viewListAccount(json).then(function(response) {


if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success')

$scope.tableData =;



If you want to trigger viewAccount() every time something is typed you should use ng-change.

<input type="text"  class="form-control" ng-model="selectedGcode" placeholder="Search" ng-change="viewAccount()" /></th>

If you want to trigger viewAccount() specifically on a click, you should use a button instead.

<input type="text"  class="form-control" ng-model="selectedGcode" placeholder="Search"/></th>
<button type="button" class="btn btn-default" ng-click="viewAccount()"></button>