Im using an index.ts file to encapsulate exports as mentioned in the angular 2 style guide (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure).
This worked fine across the app Im writing, but for some reason in one service that im trying to inject into another service this causes a strange Error.
The exported class:
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 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 that caused 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 Error thrown by the browser:
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 you can see the UserIds class is undefined in the params of the constructor.
Changing the UserIds import to the source file fixed the problem:
import {UserIds} from "../user_ids.service/user_ids.service";
Still I want to keep the older style on this using the index.ts as all other services and components in my app, and also understand why did this happen.