I have a problem accessing a variable that must be resolved by the service. If I use this variable directly from angular in html, there is no problem, but when I want to use it in a method, I become nothing. The service is working fine and this is a call to the http rest service. Here is the Controller:
module domain {
import DataAccessService = domain.DataAccessService;
import IDocument = domain.IDocument;
import DocumentEntity = domain.DocumentEntity;
import IEntity = domain.IEntity;
import Structure = domain.Structure;
interface IDocListController {
response: IEntity;
locations: IEntity;
structures: IStructure[];
}
export class DocController implements IDocListController {
title: string;
response: domain.IEntity;
locations: domain.IEntity;
structures: IStructure[];
static $inject = ["DataAccessService", "$scope"];
constructor(private dataAccessService: DataAccessService, $scope) {
this.title = "Document Listing";
var documentResource = dataAccessService.getDataResource();
documentResource.query((data: domain.IEntity) => {
this.response = data;
});
$scope.vm = this;
console.log($scope.vm);
if (!this.response || !this.response.folders.length) {
console.log("NO RESPONSE RETURNING NOTHING");
return;
}
this.structures = this.createFolderStructure(this.response.folders, 4);
console.log(this.structures);
}
createFolderStructure(folders: IFolder[], depth: number): IStructure[] {
var structures: Structure[] = [];
for (var i = 0; i < folders.length; i++) {
let str: Structure = new Structure();
str.id = folders[i].id.toPrecision();
str.isFolder = true;
str.name = folders[i].name;
str.structures = this.createFolderStructure(folders, depth - 1);
structures.push(str);
}
console.log(structures);
return structures;
};
}
And the service is as follows:
module domain {
import DocumentEntity = domain.DocumentEntity;
export interface IDataAccessService {
getDataResource(): ng.resource.IResourceClass<IEntityResource>;
}
export interface IEntityResource extends ng.resource.IResource<domain.Entity> {
}
export class DataAccessService implements IDataAccessService {
static $inject = ["$resource"]
constructor(private $resource: ng.resource.IResourceService) {
console.log("DataAccessService Constructor");
}
getDataResource(): ng.resource.IResourceClass<IEntityResource> {
console.log("REST CALL");
return this.$resource("http://localhost:8080/services/name/:searchId/documents/", {searchId: "12345678"}, {
'query': {
method: 'GET',
isArray: false
}
});
}
}
angular.module("common.services", ["ngResource"]);
}
source
share