Angular 2 stil kılavuzunda (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure) belirtildiği gibi dışa aktarmak için bir index.ts dosyası kullanıyorum.
Bu, uygulama boyunca iyi çalıştı Im yazıyor, ama bir nedenle bir hizmette başka bir servise enjekte etmeye çalışıyorum bu garip bir Hataya neden olur.
Dışa aktarma sınıfına index.ts dosyası kullanmak, enjekte edilen kurucuda undefined neden olur
ihraç sınıfı:
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;
}
}
index.ts dosyası:
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"
Hata (ithal dosyası) neden kodu:
import {UserIds} from "../index";
import {Http} from 'angular2/http';
@Injectable()
export class HttpRest{
constructor(
public _http: Http,
public userIdsx: UserIds
){}
...
}
Tarayıcı tarafından atılan hata:
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.
UserIds sınıfının, kurucunun paramızlarında tanımsız olduğunu görebilirsiniz. Userids kaynak dosyasına içe değiştirme
sorunu düzeltildi:
import {UserIds} from "../user_ids.service/user_ids.service";
Hala benim app diğer tüm hizmet ve bileşenler gibi index.ts kullanarak bu daha eski tarz devam etmek istiyorum ve aynı zamanda Bunun neden olduğunu anladım.
Bu konuda hala bir gelişme yok ve bunun neden olduğu konusunda hiçbir ipucu yok, diğer ihracatlarla birlikte oluyor. – wagwanJahMan
Sadece @Injectable ile olduğu gibi görünüyor. Aynı konuya sahip olmak. – rook