在AngularJS中添加带有ng-class的条件CSS类

时间:2014-11-12 11:05:31

标签: css angularjs forms

我有一个简单的问题。我想在表单提交的输入中更新我的课程。

<div class="form-group">
  <input class="form-control" ng-class="{'has-error': signup.$submitted && signup.name.$invalid}" type="text" name="name" ng-model="formData.name" required minlength="2" placeholder="Full Name">
</div>

这是我的app.js:

spinnrApp.controller('FormController', ['$scope', '$http', '$state', function (scope, http, state){

  // get list of cities and store it to select
  http.get('cities.json').success(function(data){
    scope.cities = data;
  })

  // we will store all our form data in this object
  scope.formData = {};

  // function to process the form
  scope.processForm = function(isValid) {
    scope.$submitted = true;
    if(isValid && state.$current=='registration.spinnrapp') {
      state.go('registration.artist');
    } else if(isValid && state.$current=='registration.artist') {
      state.go('registration.share');
    } else if(!isValid && state.$current=='registration.artist') {
      alert('Please make sure you have selected an artist.');
    } else if(!isValid && state.$current=='registration.spinnrapp') {
      return;
    }
  };
}]);

当我通过ng-click调用此功能执行提交时,我的signup.$submitted仍然保持为false。我也有来自这个Plunker的参考:http://plnkr.co/edit/xDIzC0A50cXxMpIHeP3C?p=preview

Plunkr更新了它的课程。为什么我的做法不一样?我做错了吗?

0 个答案:

没有答案