Nicoleta Wilskon Nicoleta Wilskon - 1 year ago 74
AngularJS Question

Using ng-change in search box

Request :

$scope.viewAccount = function(){
var json = {

"json": {
"request": {
"servicetype": "60",
"functiontype": "1014",
"data": {
"shortname": $scope.model.selectShortName,
"groupzname": $scope.model.selectGname,
"city": $scope.model.selectCity,
"state": $scope.model.selectState,
"country": $scope.model.selectCountry,
"groupzcode": $scope.model.selectGcode,
"activationstatus": true,
"details": false,
"sortbasedon": $scope.groupzname,
"orderby": "desc",


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

if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success')
$scope.tableData =;



The above function is to display all datas into table.I have a search box in groupzname,shortname and I used ng-change and called a new function changeviewAccount() removing offset in request. But the problem here I get is even if I enter one letter in searchbox, the function is getting called everytime. I am new to AngularjS .

Answer Source

Instead of ng-change , you can use ng-blur,whhich tells AngularJS what to do when an input box loses focus.

  <input ng-blur="changeviewAccount()" type="text" class="form-control"  placeholder="Title">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download