Thursday, 25 June 2015

angularjs form $setValidity




You can have this directive:

  .directive('alwaysInvalid', function() {
    return {
      require: 'ngModel',
      link: function(scope, ele, attrs, controller) {
        scope.$watch(attrs.ngModel, function() {
          controller.$setValidity('aaaassss', false);

        });
      }
    }
  });



And in your html:


  <form name="loginForm" ng-controller="formController" >
    <input name="email" ng-model="email" type='email' always-invalid />
    <input name="password" ng-model="password" required  always-invalaid/>
    <input type="submit" ng-click='submit()' />

    <pre>{{loginForm | json}}</pre>
  </form>










If you call this $setValidity('aaaassss', false);   it will apply a css onto your html tag the new css is "ng-invalid-aaaassss" then you can create a css for it.  if you call it with "true", it will not give your this css.
















No comments:

Post a comment