export class FloorPlanComponent implements AfterViewInit, OnInit {
constructor();
constructor(public _baseComponentService?: BaseComponentService,
public _internalZoneService?: InternalZoneService,
public routeParams?: ActivatedRoute,
public internalAssetService?: InternalAssetService,
public slimLoadingBarService?: SlimLoadingBarService,
private errorLoggerService?: ErrorLoggerService
) {
if (this._baseComponentService != null) {
this._baseComponentService.SetPageTitle("Zones - Internal");
}
this.imgDelZone = parentElement.append("image")
.attr("id", "delZone" + newId)
.attr("idCounter", newId)
.attr("r", "NaN")
.attr("stroke-width", 0)
.attr("opacity", 0.8)
.attr("x", function (d) { return d.x + (shapeWidth - 22); })
.attr("y", function (d) { return d.y + 1; })
.attr("style", "opacity: 1; stroke-width: 1;")
.attr("xlink:href", "../app/assets/images/Remove_Delete-22.png")
.attr("preserveAspectRatio", "none")
.attr("transform", " ")
.attr("height", 18)
.attr("width", 18)
.attr("cursor", "pointer").on("click", function() {
var comp = new FloorPlanComponent();
comp.promptDeleteZone(this);
});
}
在“click”函数中,我想用它来引用我的类。但它将此称为窗口对象。为了解决这个问题,我在无参数构造函数的帮助下创建了一个类的对象。但据此,我无法获得任何服务。请帮忙。在TypeScript中,创建具有http构造函数的相同类的对象
感谢亚历山大快速回复。我还有一个场景被卡住了。见下面的代码。 drag:any = d3.drag()。on(“drag”,this.dragmove);在dragmove(d)函数中,我希望将其作为平面布局组件以及获取所选拖动项目的此对象。这怎么可能。 –
你可以在局部变量中保存指向'this'的指针并使用闭包来访问它: 'let self = this; drag:any = d3.drag()。on(“drag”,function(){ let dragItem = this; self.dragmove(dragItem); });' –
它不起作用。我用self:any = this; (在类的根级别)。在函数内部,自身仍然指窗口对象。 –