1
I’m studying AngularJS
and I’m trying to make a CRUD
simple, however I am not able to have the same object of my listing for my form, that is, at the time you click the edit button go to the form filled by the object.
I have the Factory
(I read about sharing data but only attribute, wanted to share the whole object)
app.factory('item', function(){
return item;
});
My list:
<tbody>
<tr ng-repeat="item in lista">
<td>{{item.id}}</td>
<td>{{item.descricao}}</td>
<td>{{item.status}}</td>
<td>{{item.prioridade}}</td>
<td>{{item.tipo}}</td>
<td>
<a class="btn" href="#" ng-click="editItem(item)"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn" href="#" ng-click="deleteItem(item)"><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
</tbody>
And my Controllers
app.controller("listCtrl", function($scope, $http, $location, item){
$scope.itemAux = item;
$scope.loadData = function(){ ... };
$scope.deleteItem = function(item){ ... };
$scope.editItem = function(itemX){
$scope.itemAux = itemX;
$location.path('/cadastro');
};
}
app.controller("formCtrl", function($scope, $http, $location, item){
$scope.itemAux = item;
$scope.save = function(){ ... }
$scope.update = function(){ ... }
}
http://stackoverflow.com/questions/12008908/angularjs-how-can-i-pass-variables-between-controllers
– DiegoAugusto