0

I have been trying to create a factory that can be called from a controller. But am unable too.

My patientview.html:

<pThis is the patientsearch view.</p
 <button type="button" class="btn btn-large btn-block btn-default" ng-click="click()">button</button>

My patientviewController:

module tsRisApp {
export interface IPatientregistrationScope extends ng.IScope {
click:any;
data: any[];
}
export class PatientviewCtrl {
constructor (private $scope: IPatientregistrationScope) {
  $scope.click = function(){
    let data = patientFactory().SearchPatients("Doe");
   }
}       
}
}

angular.module('tsRisApp')
  .controller('PatientViewCtrl', tsRisApp.PatientViewCtrl);

And this is my patientFactory:

'use strict';

module tsRisApp {
 export function patientFactory() {
   return new Patientfactory();
 }


export class Patientfactory {
static $inject = ['$http', '$location'];
http: ng.IHttpService;
location: ng.ILocationService;

constructor () {
   }

SearchPatients(searchString:string) {
  let request = new Request();
  request.Compression = "no"
  request.ServiceType = "SearchPatients"
  request.SessionId = "SessionLessRequest"
  request.Parameters = searchString;
  let jsonRequest = JSON.stringify(request);
  this.http.post("http://" +this.location +"request.php/", jsonRequest).then(function (response) {
    return response.data;
  })

}
}
}

When clicking the button I get the following error:

angular.js:13920 TypeError: Cannot read property 'post' of undefined

What am I missing? Thanks for your help

0

1 Answer 1

1

I believe on your constructor, it should be:

export class Patientfactory {

static $inject = ['$http', '$location'];

constructor (private http: ng.IHttpService, 
             private location: ng.ILocationService) {}

SearchPatients(searchString: string) {

  //Then you can access your http.post 
  this.$http.post()

}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.