我在學習使用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個月的一部分,將非常感激。