I am trying to achieve Master-Detail View based on a JSON file. The PHP functions well. It brings the data as it is supposed to be. Config.js, or controller.js are working fine. However, I am getting an error as shown below. The SET property is undefined.
I am a beginner. I thought putting 'this.___ ' would be setting the property. But, it seems that I am missing. If not, what could be wrong? I took the reference from the below link.
Could anyone please tell me what is wrong? Perhaps, how to set the property?
(function () {
'use strict';
var app = angular.module('myProject', []);
app.service('ProjectService', function($http) {
$http.get("projects_read.php", {})
.then(function(response){
var pjts = response.data;
this.getProjects = function() { //ERROR occurs
return pjts;
};
this.getProject = function(id) {
for (var i = 0; i < pjts.length; i++) {
if (pjts[i].id === id) {
return pjts[i];
}
}
return null;
}
console.log(pjts);
});
})
})();
[ERROR] Cannot set property 'getProjects' of undefined.
[Reference Link] http://plnkr.co/edit/VJxlqguJZGrIutAFLCNc?p=preview
Thank you in advance for your assistance!