2
I have a ng-repeat
in Angular
whose value of each iteration is an object. By clicking a button referring to the row of the table where this object is used, a form for editing it is opened, and, with this data, fill this form.
Thus:
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>
<link rel="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>
However, I would like the value of the selected object, when edited in the form, not to immediately update the table values, but only by clicking on the "save".
How can I "break" this reference temporarily in Angular and then update it again?
Thank you very much, friend. + 1
– Wallace Maxters