I'm having an issue retrieving data from a Service in my Controller. Here is the code for my Service file:
import {IHttpService} from 'Angular';
export class MyService {
public static $inject = ['$http'];
constructor(private $http:IHttpService, private getItems){
this.getItems= function() {
this.$http.get('items.json').then(function(response){
if(err){
console.error(err);
}
console.log(response.data);
return response.data;
});
}}}
And here is the code for the Controller:
import {MyService} from './MyService';
export class MyController {
public:getData;
static inject: Array<string> = ['$http', '$scope', 'MyService'];
constructor(private $http:ng.IHttpService, private $scope:any, private MyService:any){
this.getData = function(){
MyService.getItems.then(function (data) {
this.getItems = data;
console.log(data);
});
}
}
Could someone please help me understand what's going wrong with my code? Thank you.