I'm fairly new to angularjs and have a working service. However, I want to move the patient model out of the service and into a separate javascript file. I believe I need to use a factory or service for this task, but I'm not entirely sure how to go about it.
This is my patient.service.js:
(function () {
'use strict';
angular
.module('beincharge.patient')
.factory('patientDataService', patientDataService);
patientDataService.$inject = ['$http'];
function patientDataService($http) {
var service = {
getData: getData
};
return service;
//////////
function getData() {
function patient(d) {
this.Status = d.Status;
this.ImageUrl = d.ImageUrl;
this.PersonId = d.PersonId;
this.LastName = d.LastName;
this.MiddleName = d.MiddleName;
this.FirstName = d.FirstName;
}
var data = [
{
"Status": "Active",
"ImageUrl": "http://lorempixel.com/100/100/people/9/",
"PersonId": 1,
"LastName": "Pratt",
"MiddleName": "B",
"FirstName": "Allie"
},
{
"Status": 'Active',
"ImageUrl": "http://lorempixel.com/100/100/people/3/",
"PersonId": 1,
"LastName": "Pratt",
"MiddleName": "B",
"FirstName": "Allie"
}];
return getPatientList(data);
function getPatientList(data) {
var a = [];
angular.forEach(data, function (d, i) {
a.push(new patient(d));
})
return a;
}
}
}
I want to move the model into a file called patient.model.js:
(function () {
function patient(d) {
this.Status = d.Status;
this.ImageUrl = d.ImageUrl;
this.PersonId = d.PersonId;
this.LastName = d.LastName;
this.MiddleName = d.MiddleName;
this.FirstName = d.FirstNa
}
return patient;
}());