When using AngularJS for insert and update operations, I encounter a problem where changes made to user data are reflected in the list of users. Additionally, when adding a new user, the last record's data populates all input fields.
Code:
User List:
<tr ng-repeat="user in users">
<td>
<a href="#" ng-click="openPopUp(user)">
<div class="edit-icon"></div>
</a>
</td>
</tr>
Add and Update Part:
<input type="text" name="firstname" ng-model="user.firstname" >
<input type="text" name="lastname" ng-model="user.lastname" >
Controller:
$scope.users = [];
$scope.user = {};
$scope.openPopUp = function (user) {
$scope.user = user;
ngDialog.open({
templateUrl: 'templateId',
scope: $scope
});
}
$scope.save = function () {
$scope.users.push($scope.user);
ngDialog.close();
}