ここに私のJSコードがあります。入力値を更新すると、angularJSの配列の対応する入力値がすべて更新されます
angular.module('myApp', [])
.controller("myController", [function() {
this.master = [];
this.addUser = function(user) {
this.master.push(user)
};
this.removeUser = function(user) {
var indexToRemove = this.master.indexOf(user);
this.master.splice(indexToRemove,1)
}
this.reset = function() {
this.user = this.master[this.master.length - 1];
}
}])
ここは私のHTML部分です。
<body ng-app="myApp" ng-controller="myController as Cntrl">
<form>
Name: <input type="text" ng-model="user.name" /> <br />
Email: <input type="email" ng-model="user.email" /> <br />
Gender: <input type="radio" ng-model="user.gender" value="male" /> Male
<input type="radio" ng-model="user.gender" value="female" /> female <br /> <br />
<input type="button" ng-click="Cntrl.addUser(user)" value="Add User">
<input type="button" ng-click="Cntrl.reset()" value="Reset User">
</form>
<div ng-repeat="users in Cntrl.master track by $index">
<span ng-click="Cntrl.removeUser(users)" >X</span> <pre>{{users | json}}</pre>
</div>
</body>
新しいユーザーを追加して、選択したユーザーを削除できます。しかし、新しいユーザーを追加するたびに、アレイ内のすべての古いユーザーのプロパティが、新しく追加されたユーザーのプロパティで更新されています。
ここで間違いを説明してください。