I have ng-repeat
in Angular
whose value of each iteration is an object. When I click on a button referring to the table row where this object is used, a form for editing it is opened, and with that data I fill out this form.
So:
angular.module('app', [])
.controller('Test', function ($scope) {
$scope.users = [
{name: 'Wallace', email: '[email protected]'},
{name: 'Wayne', email: '[email protected]'}
];
$scope.edit = function (user) {
$scope.user = user;
}
});
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><linkrel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css">
</head>
<body>
<div ng-controller="Test" class="container">
<table class='table'>
<tr ng-repeat="user in users">
<td>Name: {{ user.name }}</td>
<td>E-mail: {{ user.email }}</td>
<td><button class="btn btn-primary" ng-click="edit(user)">editar</button></td>
</tr>
</table>
<form ng-if="user">
<input type="text" ng-model="user.name" class="form-control" />
<input type="email" ng-model="user.email" class="form-control" />
<button type="submit" ng-click="save()" ng-click="save()" class="btn btn-primary">Salvar</button>
</form>
</div>
</body>
</html>
But I would like the value of the selected object, when being edited in the form, not to immediately update the values of the table, but only when clicking the "save" button.
How can I "break" this reference temporarily in Angular and then refresh it again?