1
<div class="row" ng-switch on="patienttype">
<hr>
  <div class="col-lg-4">
    <div class="panel-body" ng-switch-when="Outpatient">
      <div class="form-group">
         <label>Attending Physician</label>
         <input type="text" placeholder="Dr. Juan Dela Cruz" ng-model="attendingdoctor">
      </div>
    </div>
  </div>
</div>

I'm trying to do an angularjs post but the input data doesn't bind to the model when doing the post. Here's the code for the controller

$scope.Register = function() {
      $http.post("http://localhost/Metro Lipa Patient System/metro-lipa-pages/patient-details.php", {
           'attendingdoctor': $scope.attendingdoctor
           }).then(function(response){
           window.location.href = 'index.php'
           });
  };

What could be the thing that I'm doing wrong?

This is php script after posting the data

<?php
require_once '../assets/connection.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$attendingdoctor = addslashes($request->attendingdoctor);

?>
  • 2
    Possible duplicate of [angularjs - ng-switch does not bind ng-model](https://stackoverflow.com/questions/15593299/angularjs-ng-switch-does-not-bind-ng-model) – Azad Nov 09 '17 at 06:36
  • Why do you not use response. If you use location.href your angular js module will load again and this is not an angular way. – hurricane Nov 09 '17 at 06:38
  • ng-switch creating its own scope use `$scope.$parent.attendingdoctor` – Azad Nov 09 '17 at 06:38
  • Good day @hurricane, I'm still learning angular and consider me as a beginner so if there's a better way of doing that keep me posted. – Jed Matthew Lina Nov 09 '17 at 06:40
  • @JedMatthewLina Okey then. Can you add "request object example" and "response object example" for patient-details.php service. – hurricane Nov 09 '17 at 06:42
  • Still the same thing @azad, doesn't post the data. I'm thinking, Is there any other way of doing this? – Jed Matthew Lina Nov 09 '17 at 06:44
  • @hurricane What I did with request object was this `$postdata = file_get_contents("php://input"); $request = json_decode($postdata); $attendingdoctor = addslashes($request->attendingdoctor);` What is the better way? – Jed Matthew Lina Nov 09 '17 at 06:55
  • @JedMatthewLina I mean can you show us your request and response JSON data on question? – hurricane Nov 09 '17 at 06:57
  • @hurricane Okay, I updated the script above. What am I doing wrong? – Jed Matthew Lina Nov 09 '17 at 07:02

0 Answers0