I am studying AngularJS
and I am trying to make a CRUD
simple, but I am not able to have the same object of my listing for my form, that is, when I click the edit button go to the completed form by the object.
I have Factory
(I read about sharing data but only attribute, I wanted to share the entire 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(){ ... }
}