1
I have some sensitive variables, and the ideal would be 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 catch the url
which in this case is a sensitive variable to use in all my requests, this service and others.
private url: string = padrao + "ListarEstados.ashx";
I’m trying to use the AppModule
for this I did, 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'
Be advised not to use this.url method in appModule
– Renan Rodrigues
[ts] Property 'url' does not exist on type 'Appmodule'
– Renan Rodrigues
[ts] Property 'Appmodule' does not exist on type 'Restaurantesprovider'.
– Renan Rodrigues
You imported your Appmodule class?
import { AppModule } from './../../model/appModule';
– NilsonUehara
It really isn’t that, I tried but it didn’t work
– Renan Rodrigues
It is worth noting that I am taking this data from the service
– Renan Rodrigues