检查表格是否被触摸

时间:2016-04-07 13:35:13

标签: angularjs forms validation

在角度我想要这样做

<script>
  //inside the controller
  $scope.myForm.$dirty{
    //hide some divs etc.
  }
</script>

如何在JavaScript中完成此操作,而不在HTML中进行任何验证?

更新

<form id="loginform" name="loginform" ng-submit="login()" novalidate>
<input type="text" class="form-control" id="username" name="username" ng-model="username" ng-click="hideInvalidUsername()" placeholder="Username" autofocus required>

</form>

并在我的控制器中

  app.controller('myCtrl', ['$scope', 'localStorageService' ,
  function ($scope, localStorageService ) {  

if($scope.loginform.$dirty) { alert("yo"); }

1 个答案:

答案 0 :(得分:2)

你的问题不太清楚,但我想你想这样做:

<form name="myForm">
    <input type="text">
    <span class="message" ng-show="myForm.$dirty">the form is dirty</span>
</form>

表单将自动绑定到具有name属性

的变量中的范围