Tuesday, 8 March 2016

ng-change



ng-change can be used to capture any action performed by the user with input type tag, select tag.

Using ng-change with input type :


<input type="number" class="form-control" ng-change="calculate()" />

Here ng-change modal will go to calculate() in the controller of this page at the time of change text in the textbox. This is same as writing a onTextChange() action on the textbox.

On Controller:

$scope.calculate = function () {

//Do the required operation here.
}



Using ng-change with select tag :


<select ng-options="size as size.name for size in sizes" 
   ng-model="item" ng-change="update()"></select>



Here the ng-change will be called when user will select an option. 

No comments:

Post a Comment