Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set scope variable value in angularjs template

Tags:

angularjs

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.

like image 677
VBMali Avatar asked Jan 02 '26 07:01

VBMali


1 Answers

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;
      }
});
like image 102
adt Avatar answered Jan 04 '26 14:01

adt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!