Thanks to some experts out there who helped me a few hours ago, I could move on to the next level. Here I face probably a trivial issue but for a novice like me, it is a difficult one.
As the title represents, I was returned with 'get' of undefined even though I was using $http.get which worked well in other function.
What am I missing or doing wrong? Could anyone help me?
[ERROR MSG]
TypeError: Cannot read property 'get' of undefined
[app.js]
(function () {
'use strict';
angular.module('myProject', [
])
.service('ProjectService', function($http) {
var pjts = {};
this.$http.get("projects_read.php", {}). // I have'get' here.
.then(function(response){
var pjts = response.data;
this.getProjects = function() {
return pjts;
};
});
this.getProjects = function() {
return pjts;
},
this.getProject = function(id) {
for (var i = 0; i < pjts.length; i++) {
if (pjts[i].id === id) {
return pjts[i];
}
}
return null;
}
}.bind(this))
})();
Thank you so much in advance and hope you have a great day!
.bind(this)in the second line from the end? That's going to cause problems.