How to use routeParams in $ http.get so it returns only 1 object? I want to bring only the object that has the same ID passed in routeParams.
<a href="funcionario/edit/{{funcionario.id}}" class="btn btn-primary btn-xs" ng-click="">
Editar
</button>
Clicking edit is directed to the page with the correct id. For example: localhost / official / edit / 98. I use the routes below.
var app = angular.module('funci',
['ngRoute','ui.bootstrap','angular-confirm','ngSanitize' ]);
app.config(function($routeProvider, $locationProvider){
$locationProvider.html5Mode(true);
$routeProvider.when('/funcionarios', {
templateUrl: 'partials/funcionarios.html',
controller: 'FuncionariosController'
});
$routeProvider.when('/funcionario/novo', {
templateUrl: 'partials/funcionario.html',
controller: 'FuncionarioController'
});
$routeProvider.when('/funcionario/edit/:id', {
templateUrl: 'partials/funcionario.html',
controller: 'FuncionarioController'
});
$routeProvider.otherwise({
redirectTo: '/funcionarios'
});
});
On this page, I use a different controller, called: officialController. It is in this controller that I am trying to console.log only in the id object passed in routeParams, however I can not get it.
app.controller('FuncionarioController', function($scope, $http, $routeParams){
$scope.funcionario = {};
$http.get('http://localhost/project-funci/api/getData.php' + $routeParams.id)
.then(function(funcionario) {
$scope.funcionario = funcionario.data;
console.log($scope.funcionario);
});
The getdata.php:
<?php
include "connect.php";
$query = "select * from funcionario";
if ($result = mysqli_query($dbc, $query))
{
while($row = $result->fetch_object())
{
foreach($row as $key => $col){
$col_array[$key] = utf8_encode($col);
}
$row_array[] = $col_array;
}
echo json_encode($row_array, JSON_NUMERIC_CHECK);
}
mysqli_close($dbc);
?>
Result of getData.php
[{"id": 98, "cod_equipment": 1, "cod_chargo": 1, "name": "
Currently, the console.log returns printed the entire html of the page.
Please, could anyone help me?