Sensitive and global ionic 3 and angular 4

1

I have some sensitive variables, and it would be ideal to leave all the variables in one environment, when it is necessary to change, for example from production to development, this task becomes easy.

Ex:

@Injectable()
export class RestaurantesProvider {
private url: string = "http://199.169.9.9/ws/ListarEstados.ashx";
  constructor(private http: Http) {
    console.log(this.url);
  }

getRestaurantes(){
  return this.http.post(this.url, null)
  .do(this.logResponde)
  .map(this.extractData)
  .catch(this.catchError);
}

private catchError(error: Response | any){
  console.log(error);
  return Observable.throw(error.json().error || "Erro de conexção");
}

private logResponde(res: Response){
  console.log(res);
}

private extractData(res: Response){
  return res.json();
}
}

By default I would like to get the url which in case it is a sensitive variable to use in all my requests, this service and the others.

private url: string = padrao + "ListarEstados.ashx";

I'm trying to use AppModule for this done, so I did so:

export class AppModule {
   private url: string = "http://199.169.0.9/ws/ListarEstados.ashx";

   getUrl(){
     return this.url;
   }
}

And in my classe I do so:

private url: string = AppModule.getUrl();

The getUrl() is marked and this message appears

  

[ts] Property 'getUrl' does not exist on type 'typeof AppModule'

    
asked by anonymous 05.06.2017 / 21:27

2 answers

1

Change your AppModule object by adding the static modifier:

export class AppModule {
   private static url: string = "http://199.169.0.9/ws/ListarEstados.ashx";

   static getUrl(){
     return this.url;
   }
}

And to receive this data is enough:

private url: string = AppModule.getUrl();

Remembering to instantiate the class, like this:

import { AppModule } from '../app/app.module';
    
06.06.2017 / 22:55
-2

Use

import { MyApp } from '../../app/app.component' 

instead of this import .

    
06.07.2018 / 15:02