angularjs - Cannot read property $valid of undefined -
i have form -
<form name="myform" novalidate>
there fields in form validating , submitting form -
<input type="button" ng-click="save(data)" value="save">
in controller, want check if form not valid save()
should show error on page. that, setting watch -
$scope.$watch('myform.$valid', function(validity) { if(validity == false) // show errors });
but getting error on running -
cannot read property '$valid' of undefined
can explain why?
thanks
you misspelled "myform" in controller code. in order remove error, write "myform" instead of "myform".
however expect want this.
$scope.save = function(data){ alert($scope.myform.$valid); }
i setup jsfiddle.
Comments
Post a Comment