Good morning. I'm assuming you're using routing and programming a SPA, so I'll build on this to give you an answer.
In your edit button you must indicate that you change your view, for example:
<button ng-click="edit(company)">Editar</button>
In your controller you define the edit function:
$scope.edit = (company) => {
$location.path('editar/${company._id}');
};
This will change your path to something like this: /editar/n4503nc
. You are supposed to have that URL mapped in the router:
$routeProvider
...
.when('/empresas/editar/:id', {
template: 'editar-empresa.html',
controller: 'EditCompanyCtrl'
});
The EditCompanyCtrl
will receive the id
parameter that contains the company ID to edit. In the controller what you should do is make a request to the backend via AJAX and obtain the company data with that ID. Once obtained, you only add it to $scope
.
app.controller('EditCompanyCtrl', ($scope, $routeParams) => {
$.get('/api/companies/${routeParams.id}')
.then((company) => {
$scope.company = company;
});
});
For a modal, there is no greater mystery. Just have the modal under the command of the same controller.