这是我的注册表单,我希望所有表单字段都使用angular存储在json字符串变量中,然后将该json字符串发布到某个url。当用户注册时,它必须显示"已成功注册"消息,但如果email_id或用户名已经存在,服务器应该发送错误的表单数据。以下是注册表。
<form name="myForm" class="register--form" ng-submit="register()" novalidate>
<fieldset>
<input class="register--first-input" type="text" name="firstname" placeholder="First Name" ng-model="user.firstname" ng-required="true">
<p class="error validationerror" ng-show="myForm.firstname.$invalid && myForm.firstname.$touched">You must enter your first name.</p>
<input class="register--last-input" type="text" name="lastname" placeholder="Last Name" ng-model="user.lastname" ng-required="true">
<p class="error validationerror" ng-show="myForm.lastname.$invalid && myForm.lastname.$touched">You must enter your last name.</p>
<input class="register--email-input" type="email" name="email" placeholder="Email" ng-model="user.email" ng-required="true">
<p class="error validationerror" ng-show="myForm.email.$invalid && myForm.email.$touched">Must be a valid email.</p>
<input class="register--password-input" type="password" name="password" placeholder="Password" ng-model="user.password" ng-required="true">
<p class="error validationerror" ng-show="myForm.password.$invalid && myForm.password.$touched">You must enter a password.</p>
</fieldset>
<button type="submit" class="register--submit" ng-disabled="myForm.$invalid">Register</button>
<span>or</span>
<a class="login--register" ng-href="#/login">Login</a>
</form>
以下是登录表单
<form name="form" ng-submit="vm.login()" role="form">
<div class="form-group" ng-class="{ 'has-error': form.username.$dirty && form.username.$error.required }">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" ng-model="vm.username" required />
<span ng-show="form.username.$dirty && form.username.$error.required" class="help-block">Username is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.password.$dirty && form.password.$error.required }">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control" ng-model="vm.password" required />
<span ng-show="form.password.$dirty && form.password.$error.required" class="help-block">Password is required</span>
</div>
<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">Login</button>
<a href="#/register" class="btn btn-link">Register</a>
</div>
</form>
答案 0 :(得分:0)
在你点击按钮的控制器中创建一个类似的变量,它将具有与ng modle相同的键中的值
$scope.show={};