1
我有一個$ 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
變量,因爲當我更新沒有窗體控件更新。雖然如果我刪除表單名稱,那麼它的作品。不過,我需要表單名稱來進行適當的表單驗證。
任何人都知道我可以如何將表單控件綁定到範圍對象,但也保持表單驗證?
沒有想到!謝謝 – iamjonesy
你能詳細說一下n00b到#AngularJS嗎?我現在正在討論這個問題,並想知道最佳做法是什麼。我只是用類似的名字引用它們,但認爲在我完全理解它之前,這將繼續成爲一個混亂點。 – kalisjoshua