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);

?>
9
  • 2
    Possible duplicate of angularjs - ng-switch does not bind ng-model Commented Nov 9, 2017 at 6: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. Commented Nov 9, 2017 at 6:38
  • ng-switch creating its own scope use $scope.$parent.attendingdoctor Commented Nov 9, 2017 at 6: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. Commented Nov 9, 2017 at 6:40
  • @JedMatthewLina Okey then. Can you add "request object example" and "response object example" for patient-details.php service. Commented Nov 9, 2017 at 6:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.