Angular2:将从服务加载的变量分配给从另一个服务加载的值
Angular2 :Assigning a variable loaded from a service to a value loaded from another service
我在 angular2 应用程序中使用服务,我正在从调用 json 数据的 2 个服务加载参数。
我的问题是如何影响从服务 1 加载的变量到从服务 2 加载的值
我的代码如下所示:
service 1 : ParamService(此服务使用 class "dormant")
服务 2:FormeService
// Rectangle
if (this.formeGeoChoisi == 302){
this.ParamService.dormant.Rect_ON = 1.00
}
// Triangle Total
if (this.formeGeoChoisi == 303){
this.ParamService.dormant.Triangle_ON = 1.00
}
// Triangle Partiel
if (this.formeGeoChoisi == 304){
this.ParamService.dormant.DemiHexag_ON = 1.00
}
// Inclinaison gauche totale
if (this.formeGeoChoisi == 305){
this.ParamService.dormant.TriangleG_ON= 1.00
// Rectangle
if (this.formeGeoChoisi == 302){
this.ParamService.dormant.Rect_ON = 1.00
}
// Triangle Total
if (this.formeGeoChoisi == 303){
this.ParamService.dormant.Triangle_ON = 1.00
}
// Triangle Partiel
if (this.formeGeoChoisi == 304){
this.ParamService.dormant.DemiHexag_ON = 1.00
}
// Inclinaison gauche totale
if (this.formeGeoChoisi == 305){
this.ParamService.dormant.TriangleG_ON= 1.00
你可以注意到我正在处理每个案例以影响1:00的正确参数(Rect_ON,Triangle_On ...)
所以我开发了 服务 2,其中包含所选参数 (formeGeoDormant) 我想直接影响它所以我这样做是为了通过 if 循环简化和避免所有:
this.ParamService.dormant.(this.formeService.formeGeoDormant)= 1.00
但这没有用,我该怎么办(正确的语法)??
假设 this.formeService.formeGeoDormant
returns 一个 string
of on of " (Rect_ON , Triangle_On ... )", 这应该有效
this.ParamService.dormant[this.formeService.formeGeoDormant]= 1.00
我在 angular2 应用程序中使用服务,我正在从调用 json 数据的 2 个服务加载参数。
我的问题是如何影响从服务 1 加载的变量到从服务 2 加载的值
我的代码如下所示:
service 1 : ParamService(此服务使用 class "dormant")
服务 2:FormeService
// Rectangle
if (this.formeGeoChoisi == 302){
this.ParamService.dormant.Rect_ON = 1.00
}
// Triangle Total
if (this.formeGeoChoisi == 303){
this.ParamService.dormant.Triangle_ON = 1.00
}
// Triangle Partiel
if (this.formeGeoChoisi == 304){
this.ParamService.dormant.DemiHexag_ON = 1.00
}
// Inclinaison gauche totale
if (this.formeGeoChoisi == 305){
this.ParamService.dormant.TriangleG_ON= 1.00
// Rectangle
if (this.formeGeoChoisi == 302){
this.ParamService.dormant.Rect_ON = 1.00
}
// Triangle Total
if (this.formeGeoChoisi == 303){
this.ParamService.dormant.Triangle_ON = 1.00
}
// Triangle Partiel
if (this.formeGeoChoisi == 304){
this.ParamService.dormant.DemiHexag_ON = 1.00
}
// Inclinaison gauche totale
if (this.formeGeoChoisi == 305){
this.ParamService.dormant.TriangleG_ON= 1.00
你可以注意到我正在处理每个案例以影响1:00的正确参数(Rect_ON,Triangle_On ...)
所以我开发了 服务 2,其中包含所选参数 (formeGeoDormant) 我想直接影响它所以我这样做是为了通过 if 循环简化和避免所有:
this.ParamService.dormant.(this.formeService.formeGeoDormant)= 1.00
但这没有用,我该怎么办(正确的语法)??
假设 this.formeService.formeGeoDormant
returns 一个 string
of on of " (Rect_ON , Triangle_On ... )", 这应该有效
this.ParamService.dormant[this.formeService.formeGeoDormant]= 1.00