我在下面,很簡單angular2服務:Angular2 - 類屬性是不確定的,即使它被設置
@Injectable()
export class DrawingService {
private _draw:Draw;
constructor(private mapSvc:MapService) {}
initialize(geometry: GeometryType):void {
this._draw = new Draw(this.mapSvc.getMap());
this._draw.on("draw-end", this.addGraphic);
this._draw.activate(geometry);
}
addGraphic(evt):void {
this._draw.deactivate();
}
}
在initialize
,我設置方法addGraphic
作爲回調。現在的問題是,在addGraphic
方法執行中,this._draw
未定義。
這裏有什麼問題?
從哪裏調用'initialize(geomotry)'? – Martin