0
How to use routeParams in $http.get to return only 1 object? I want to bring only the object that has the same ID passed in the nightParams.
<a href="funcionario/edit/{{funcionario.id}}" class="btn btn-primary btn-xs" ng-click="">
Editar
</button>
By clicking edit is directed to the page with the correct id. For example: localhost/funcio/Edit/98. 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: funcioController. It’s in this controller that I’m trying to give a console.log only on the id object passed on routeParams, but I can’t 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);
});
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_equipe":1,"cod_cargo":1,"name":"Fulano","matricula":7414}
Currently, the console.log returns printed the entire html of the page.
Please, could someone help me?