更新對象應該被修改NG-表單提交的一個空對象但
控制器
chitchatApp.controller('chitchatCtrl', ['$scope', function($scope) {
$scope.users = [
{'username': 'John'},
{'username': 'Dan'},
{'username': 'Judy'},
{'username': 'Michael'},
{'username': 'Rebecca'},
{'username': 'Macy'},
{'username': 'Ross'}
];
name = {'username': ''};
//name = {};
$scope.createuser = function createuser() {
$scope.users.push(name);
};
}]);
HTML
<body ng-app="chitchatApp" ng-controller="chitchatCtrl">
<!-- users that are currently log on will be here -->
<div class="users_container">
<div class="span2">
Here are the users that are currently log in
<li ng-repeat="user in users">
{{user.username}}
</li>
</div>
</div>
<form class="simple-form" ng-submit="createuser()">
Log in As:
<input type="text" ng-model="name.username">
<input type="submit"/>
</form>
</div>
</body>
這是我建立在角JS形式
<form class="simple-form" ng-submit="createuser()">
Log in As:
<input type="text" ng-model="name.username">
<input type="submit"/>
</form>
的NG-模型綁定到一個空對象在我的控制器
name = {};
我嘗試了修改到這個問題,以及
name = {'username': ''};
我有這樣
我$範圍的方法$scope.createuser = function createuser() {
$scope.users.push(name);
};
$ scope.users是一個包含對象的數組,每個對象都具有「用戶名」相同的屬性
我使用ng-repeat循環遍歷用戶中的用戶。
當我點擊提交,有一個新的李,但對象中的內容消失。我沒有建立數據庫。它純粹的javascript和角度js。
是在沒有得到修改 或 我有沒有成功的表格模型對象,但它消失的時候了,我注意到,當我把一個對象到一個數組(顯示了NG-重複)然後刷新,然後消失因爲它不會持續?我沒有建立數據庫?
請出示的控制器和HTML代碼的完整的相關部分。 – Bart
@Bart ok剛剛發佈 – Jngai1297