1

Estoy empezando con Angular y el framework slim. Quisiera saber si alguien me podría explicar como almacenar los datos recibidos en el Json y como interpretarlos en una tabla de un formulario HTML. El detalle es que tengo cuatro archivos y la mayoría de los tutoriales o páginas sólo tienen tres archivos.

El primer archivo es la vista busqueda.html:

<div class="col" ng-controller="busquedaCtrl">
        <center>
            <h1>Noticias</h1>

            <table
                style="width: 75%; border-collapse: separate; border-spacing: 5px 5px; color: grey; box-shadow: 6px 6px 10px black;">
                <tr ng-repeat="reporte in data">
                <tr>
                    <td>
                        <p style="color: white;" align="right">Fecha:{{reporte.fecha}}</p>
                        <h1 style="color: white;" align="left">Categor&iacute;a:</h1>

                    </td>
                    <br>
                </tr>
                <tr>
                    <td><center>
                            <span style="color: black; text-align: center;">{{reporte.categoria}}</span>
                        </center></td>
                    <br>
                </tr>
                <tr>
                    <td><h2 style="color: white;" align="left">
                            Incidente:
                            </h1></td>
                    <br>
                </tr>

                <tr>
                    <td><center>
                            <span style="color: black; text-align: center;">{{reporte.incidente}}</span>
                        </center></td>
                    <br>
                </tr>
                <tr colspan="2">
                    <td><center>
                            <img align="middle" src="{{reporte.imagen}}"
                                style="width: 75%; height: 80%;">
                        </center></td>
                    <br>
                </tr>
                <tr>
                    <td><h3 style="color: white; text-align: left;">
                            Descripci&oacute;n:
                            </h4></td>
                </tr>

                <tr>
                    <td><p style="color: black; text-align: center;">{{reporte.descripcion}}</p></td>
                </tr>

                <tr>
                    <td><h3 style="color: white; text-align: left;" align="left">
                            Estatus:
                            </h4></td>
                </tr>
                <tr>
                    <td><center>
                            <span class="label label-success">{{reporte.estatus}}</span><br>
                        </center></td>
                </tr>
                </tr>
                <br>
            </table>

El segundo archivo es el servicio.php:

$app->group('/svc/',
    function () {

$this->post('consultarNoticias', function($req, $res, $args) {

                $r = json_decode($this->request->getBody());

                    $response = array();
                    $db = new DbHandler();

                    $records =$db->query("SELECT * FROM reporte inner join categoriaemergencia on reporte.idEmergencia = categoriaemergencia.idCategoriaEmergencia INNER JOIN categoriaincidente on reporte.idIncidente = categoriaincidente.idCategoriaIncidente");


                    while ($row = $records->fetch_assoc()) {
                    //while ($row = mysqli_fetch_array($records)) {
                        //$data[] = array("tituloReporte"=>$row['tituloReporte'],"descripcion"=>$row['descripcion'],"imagen"=>$row['imagen'],"estatus"=>$row['estatus'],"tipoEmergencia"=>$row['tipoEmergencia'],"nombreIncidente"=>$row['nombreIncidente']);

                        $data[]=$row;
                    }

                    echo json_encode($data);

                    if ($records != NULL) {
                        $response['status'] = "success";
                        $response['title'] = "Consulta noticias";
                        $response['message'] = "Estas son las noticias";
                        $response['records'] = $records;
                    } else {
                        $response['status'] = "error";
                        $response['title'] = "Consulta noticias";
                        $response['message'] = "Fallo al consultar las noticias";
                        $response['records'] = $records;
                    }

            });
});


El tercer archivo es el controlador busqueda.js


app.controller('busquedaCtrl', [ '$scope', 'UserContext', 'Data', '$window', '$rootScope', 'toaster','$http'
    function($scope,$http,UserContext, Data, $window, $rootScope, toaster) {

$scope.consultarNoticias = function() {
            console.log("# AQUI TITULO : " + $scope.user.tituloReporte);        
             Data.post('consultarNoticias', { usuario: $scope.usuario
             }).then(function (results){
                if(results.status == "success"){
                    toaster.pop(200,"Bienvenido",results.message);
                    UserContext.authenticationUser(results.data);
                    $rootScope.userContextChange++;
                    $scope.userContext = UserContext.currentUser();
                    console.log("busqueda");
                }else{
                    console.log("ERROR " + results.status);
                    toaster.pop(results.status, "Error", results.message);
                }
             });

} ]);

Y el enrutador config.router.js

'use strict';

angular.module('app')
    .run(
        [ '$rootScope', '$state', '$stateParams', 'UserContext', '$window','gettextCatalog',
            function($rootScope, $state, $stateParams, UserContext, $window, gettextCatalog) {

.state('app.busqueda', {
                        url : '/busqueda',
                        templateUrl : 'vistas/busqueda.html',
                        controller : 'busquedaCtrl',
                        resolve : load([ js/controllers/busqueda.js'])
                    })

}]);

Espero que me puedan ayudar o que me pasen material con esta misma estructura. Saludos!

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.