Angular2 :Assigning a variable loaded from a service to a value loaded from another service

i’m using services in angular2 app , i’m loading parametersfrom 2 services which call json data .

my probleme is how to affect a variable loaded from service 1 to a value loaded from service 2

my code look like this :

service 1 : ParamService (this service uses a class “dormant”)

service 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

you can notice that i’m treating each case to affect the right parameter to 1:00 (Rect_ON , Triangle_On … )

so that i’ve developped service 2 which contains the choosed parameter (formeGeoDormant) and i wanna affect it directly so i ve done that to simplify and evitate all by if loops :

this.ParamService.dormant.(this.formeService.formeGeoDormant)= 1.00

but that didn’t worked , what can i do (the right syntax ) ??

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Assuming this.formeService.formeGeoDormant returns a string of on of ” (Rect_ON , Triangle_On … )”,this should work

this.ParamService.dormant[this.formeService.formeGeoDormant]= 1.00