Sunday, 15 September 2013

angularjs - Detecting value change in ng-model without using $watch and form for application having large number of models -



angularjs - Detecting value change in ng-model without using $watch and form for application having large number of models -

my application has lot of models in page. want observe whether user has changed value of model on click of save. using $watch on every model puts much load, don't want utilize method. there approach this?

small snippet below:

<div> <div class="ttere2"> <input type="radio" name="nc2-radio3" ng-model="nc2penaltyafter" value="specificdays" /> <input class="ggfe1" ng-model="nc2afterdays" ng-disabled="nc2penaltyafter!='specificdays'" type="number" min="1" max="100" step="1" value="1" />days</div> <div class="admin_wp-line"> <input type="radio" name="nc2-radio3" ng-model="nc2penaltyafter" value="immediately"/> </div> <div class="acfv1">model 1</div> </div> <div style="margin-top: 20px;"><button ng-click="savedata();">done</button></div> ............too many inputs go here </div>

use .$dirty! angular set on every element bound using ng-model, automatically, when has been changed. set on entire form. can access in code this:

if ($scope.myform.$dirty) { // code here }

angular provide 6 useful variables on form, , every ngmodel-bound element in form: $dirty , $pristine, $valid , $invalid, , $touched , $untouched. can mix , match these drive lot of useful behaviors, , they're available both in controller (using look shown above) , template (directly).

angularjs

No comments:

Post a Comment