我有一个 $rootScope 变量:
$rootScope.register_data = {};
我有一个包含表单的视图:
<form name="register_data">
<div class="popup signup">
<div class="social">
<a ng-controller="FacebookCtrl" ng-click="login()" href="javascript:void(0)" class="facebook fb-login-button">Sign up with Facebook</a>
<div class="clear"></div>
</div>
<div class="userinfo">
<div class="left"><input type="text" ng-model="register_data.firstname" placeholder="First Name" tabindex="1" required></div>
<div class="right"><input type="text" ng-model="register_data.email" placeholder="Email Address" tabindex="4" required></div>
<div class="left"><input type="text" ng-model="register_data.lastname" placeholder="Last Name" tabindex="2" required></div>
<div class="right optional"><div class="tip">optional</div><input type="text" ng-model="register_data.dob" tabindex="5" placeholder="DoB (dd/mm/yyyy)"></div>
<div class="left"><input type="text" ng-model="register_data.phone" placeholder="Phone Number" tabindex="3" required></div>
<div class="right password"><a href="javascript:void(0)" class="picker"> </a><input type="password" ng-model="register_data.password" placeholder="Password" tabindex="6" required></div>
<div class="clear"></div>
</div>
<div class="control">
<span class="terms">I agree to the <a href="javascript:void(0)">terms & conditions</a></span>
<a href="javascript:void(0)" id="terms_checkbox" class="checkbox" ng-class="{checked : terms_checked}" ng-click="changeTerms()"> </a>
<a href="javascript:void(0)" class="button" id="register_btn" ng-click="doRegister(register_data)">Sign up</a>
</div>
</div>
</form>
表单有一个名称register_data
,每个字段都通过 ng-model 绑定到该名称。$rootScope.register_data
当我更新没有任何表单控件更新时,它似乎覆盖了我的变量。虽然如果我删除表单名称,那么它就可以工作。但是我需要表单名称来进行正确的表单验证。
任何人都知道我如何将表单控件绑定到范围对象但同时保持表单验证?