4
Follow an example of code:
Controller:
$scope.filterText = {status: 'Todos', tipo: 'Todos'};
$scope.params = {page: 1, total: 10, orderBy: 'id', sort: 'desc', search: {status: '',tipo: ''}};
$scope.filterStatus = function(status, text) {
$scope.params.search.status = status;
$scope.filterText.status = text;
getProjetos($scope.params);
};
$scope.filterTipo = function(tipo, text) {
$scope.params.search.tipo = tipo;
$scope.filterText.tipo = text;
getProjetos($scope.params);
};
HTML:
<a class="btn btn-default" ng-click="filterStatus(1, 'Execução')">Status: {{filterText.status}}</a>
<a class="btn btn-default" ng-click="filterTipo(1, 'Laboratório')">Tipo: {{filterText.tipo}}</a>
To change the text of the buttons and the parameters of the query I do the assignment from inside the function without passing by parameter, changing $Scope directly, but it should not be a good practice.
I change the $scope.params
because I want to save the state of the query, for example if I click the two buttons, the first arrow the $scope.params.status = 1
and does the search, when you click on the second arrow $scope.params.tipo = 1
and makes the search, still keeping the $scope.params.status = 1
in this second search.
What are good practices for changing variables $scope
and what is the best solution in this situation?