Pass date from one input to another in AngularJS

0

Hi guys what I want to do is pick up the date that I put in one of the inputs see: create.html

<div class="form-group">
    <label for="fechaInicio">Fecha de la cita:</label>
        <div class="input-group date fecha">
    <input type="text" name="fechaInicio" class="form-control" id="fechaInicio" ng-model="cita.fechaInicio"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>

Pass it to the controller: controllers.js

$scope.getHoras = function(){
        var fechaInicio = fechaInicio;
        $http.get('../api/horas.php'),{'fechaInicio':fechaInicio}.then(function(response){
            $scope.citas = response.data;
        });
    };

make the query: hours.php

<?php
$data = json_decode(file_get_contents("php://input"));
@session_start();
$id = $_SESSION["user_id"];
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "pruebas";
$conn = new mysqli($servername, $username, $password, $dbname);
/*$sql = "SELECT hora FROM horas where $fecha and horaCompleta = '1'"*/
$sql = "SELECT hora FROM citas WHERE horaCompleta = 0 AND 'fechaInicio = $date-> fechaInicio' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
     $data = array() ;
    while($row = $result->fetch_assoc()) {
        $data[] = $row;

    }
} else {
    echo "0 results";
}
echo json_encode($data);
$conn->close();
?>

and now visualize the data collected in the create.html:

    <div class="form-group">
      <label for="hora" ng-init="getHoras()">Hora:</label>
<select ng-model="cita.hora">

<option
value="{{cita.hora}}"
ng-repeat="cita in citas">
{{cita.hora}}
</option>
</select>

If I remove this part, {'Startdate': Startdate} in controllers.js and I ask the query only in available hours if you see them but I need you to take the reference date I selected above. Thanks for the help!

EDIT: I add a photo of what I want to achieve:

Well what I intend is that when someone selects a date I visualize all the dates "empty" or all the dates occupied.

    
asked by Peter 08.12.2017 в 23:16
source

1 answer

1

Here:

$scope.getHoras = function(){
        var fechaInicio = fechaInicio;
        $http.get('../api/horas.php'),{'fechaInicio':fechaInicio}.then(function(response){
            $scope.citas = response.data;
        });
    };

You are missing the reference with the date view Start. Maybe you want to say the following:

$scope.getHoras = function(){
        var fechaInicio = $scope.fechaInicio; 
        //o vm.fechaInicio, según tengas referenciada el view model
        $http.get('../api/horas.php'),{'fechaInicio':fechaInicio}.then(function(response){
            $scope.citas = response.data;
        });
    };
    
answered by 11.12.2017 в 17:06