3

I want to set value when query textbox is empty. I want to do like this:

$scope.flag=0;

This is query textbox:

<input type="text" ng-model="query" ng-change="search()" />

When user types something, I set $scope.flag=1 in js file. Hope you catch my problem. Please do needfull.

4 Answers 4

3

HTML

  <div ng-controller="myCtrl"> 
            <input type="text" ng-model="query" ng-change="search()" />
            {{ flag }} 
    </div>

JS

app.controller('myCtrl', function($scope){
      $scope.flag=0;

      $scope.search = function() {   
         $scope.flag= $scope.query.length >0 ? 1:0;
      }
});
Sign up to request clarification or add additional context in comments.

1 Comment

I dont want to do it in js file.
1

Solved. I did it in this way:

 <input type="text" ng-model="query" ng-change="search()" /> 
    {{query=='' ? flag=0 : flag=1}}

Comments

0

You could use the ng-init directive:

<input type="text" ng-model="query" ng-init="flag=0" ng-change="search()" />

Comments

0

You can do it like this

$scope.search = function () {
    if ($scope.query.length) {
        $scope.flag = 1;
    } else {
        $scope.flag = 0;
     }
}

1 Comment

I dont want to do it in js file.

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.