Kode_12
Kode_12

Reputation: 4798

How can I add a $watcher on an input field?

Keeping in mind ng-change, I want to see how one would write a basic watch function for an input field.

How could a watch be applied to the following input field as example?

<span class="dropdown-text">
    Col <input type="text" value='tiledata.col' ng-model="tiledata.col" class="input-col" id="aeS-Col" ng-click="vm.setInputCol()">
    Row <input type="text" value='tiledata.row' ng-model="tiledata.row" class="input-row" id="aeS-Row" ng-click="vm.setInputRow()">     
    <i class= "fa fa-arrows"></i>
</span> 

Upvotes: 1

Views: 298

Answers (1)

iuliu.net
iuliu.net

Reputation: 7145

Well you have 2 input fields there. Would this work for you?

$scope.$watch('tiledata.col', function(newValue, oldValue) {
    alert('The new value of the input is ' + newValue);
});

Upvotes: 1

Related Questions