I want to validate JSON input. I know it can be done with a custom directive, but I am not capable of writing it on my own. Now I am trying to do it with ng-change.
my html:
<div class="row">
<div class="form-group col-xs-12">
<label>Custom data:</label>
<textarea class="form-control" rows="10" name="customData" ng-model="application.customDataString" ng-change="validateJSON()"></textarea>
</div>
</div>
my script
$scope.validateJSON = function () {
try {
JSON.parse($scope.application.customDataString);
} catch (e) {
$scope.applicationForm.customData.$setValidity = false;
}
return true;
}
but I am getting an error: Cannot read property '$setValidity' of undefined