Utilizing an index.ts file to manage exports, following the guidelines outlined in the Angular 2 style guide (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure), has been successful throughout my application development. However, I encountered a peculiar error when attempting to inject one service into another.
The class being exported:
import {Injectable} from "angular2/core";
@Injectable()
export class UserIds{
private _signature_id:string;
private _role_id:number;
get signature_id():string{
return this._signature_id;
}
set signature_id(id:string){
this._signature_id = id;
}
get role_id():number{
return this._role_id;
}
set role_id(id:number){
this._role_id = id;
}
}
The contents of the index.ts file:
export {Midiate} from "./midiate.service/midiate.service";
export {HttpRest} from "./http_rest.service/http_rest.service";
export {UserIds} from "./user_ids.service/user_ids.service"
The code snippet that triggered the error (the importing file):
import {UserIds} from "../index";
import {Http} from 'angular2/http';
@Injectable()
export class HttpRest{
constructor(
public _http: Http,
public userIdsx: UserIds
){}
...
}
The browser threw the following error:
EXCEPTION: Cannot resolve all parameters for 'HttpRest'(Http, undefined). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'HttpRest' is decorated with Injectable.
As observed, the UserIds class was undefined in the constructor parameters.
Resolving the issue by importing UserIds directly from the source file:
import {UserIds} from "../user_ids.service/user_ids.service";
Despite resolving the problem, my preference is to maintain the older style utilizing the index.ts like other services and components in my application, while also seeking to understand the cause of this occurrence.