javascript - How to use Angular form validation on other elements like div? -
i using angular form validation using below code
<form ng-app="" ng-controller="validatectrl" name="myform" novalidate> <p>username:<br> <input type="text" name="user" ng-model="user" required> <span style="color:red" ng-show="myform.user.$dirty && myform.user.$invalid"> <span ng-show="myform.user.$error.required">username required.</span> </span> </p> </form>
but if want use this:
<div ng-app="" ng-controller="validatectrl" name="myform" novalidate> <p>username:<br> <input type="text" name="user" ng-model="user" required> <span style="color:red" ng-show="myform.user.$dirty && myform.user.$invalid"> <span ng-show="myform.user.$error.required">username required.</span> </span> </p> </div>
but not working. there way work? without using other libraries.
jsfiddle:link
you can use ngform
directive (here) in order enable $pristine
, $dirty
, $valid
, $invalid
services within it:
just define way:
<div ng-app="" ng-controller="validatectrl" name="myform" novalidate ng-form>
here example:
Comments
Post a Comment