2015-10-07 54 views
0

我在学习使用John Kevin Basco编写的使用Flask和AngularJs构建博客(http://tutsbucket.com/tutorials/building-a-blog-using-flask-and-angularjs-part-1/)。 我已经遵循了所有的步骤,唯一要做的就是写表单模板。这是我到目前为止:AngularJs&Flask:表单模板

<form ng-submit="submit(isValid,user)" ng-model="user"> 
<h3>Email address</h3> 
<input name="email" type="email" type="submit" ng-model="user.email" value="Enter email"> 
<h3>Password</h3> 
<input name="password" type="password" ng-model="user.password" type="submit"> 
<h3>Confirm password</h3> 
<input name="password" type="password" ng-model="user.passwordConfirmation" type="submit"> 
<button type="submit">Submit</button> 
</form> 

这让我用正确的用户对象调用提交功能。我也尝试在这里添加一个动作调用,直接发送到服务器,该服务器成功创建了帐户,但将我重定向到服务器位置,而没有任何可能返回客户端的可能性。

这是我的控制器:

Blog.controller('UserCreateCtrl', function($scope, User) { 

    var defaultForm = { 
     email: '', 
     password: '', 
     passwordConfirmation: '' 
    }; 

    $scope.user = angular.copy(defaultForm); 

    $scope.submit = function(isValid, user) { 
     console.log(user); 
     $scope.submitted = true; 
     $scope.accountCreated = false; 

     $scope.userCreateForm.$setDirty(); 

     if (!isValid) { 
      return; 
     } 

     User.create(user).then(function(response) { 
      $scope.accountCreated = true; 

      // reset form 
      $scope.submitted = false; 
      $scope.user = angular.copy(defaultForm); 
      $scope.userCreateForm.$setPristine(); 
     }); 
    }; 
}) 

提交后,我得到“无法$使用setDirty不确定的”,所以问题是,userCreateForm是不确定的。

UserCreateForm可以在这里找到在服务器:

class UserCreateForm(ModelForm): 
    class Meta: 
     model = User 

如果任何人有正确的方法的线索写CREATEUSER模板形式,我,与用户的众多谁一直在问最后沿过去6个月的一部分,将非常感激。

回答

1

UserCreateForm是一个Python类,与您的javascript/angularJS代码无关。作为附注,UserCreateFormuserCreateForm是不同的标识符,因为Python和Javascript都区分大小写。我浏览了本教程,并且在Javascript中定义了userCreateForm。我认为作者的自动完成可能有点过分,你实际需要的是$scope.user.$setPristine();。我没有测试过这个,但我会试一试。