Hello, I would like to know if it is possible to set the ip address when consuming a web service rest in ionic 3, where the user could define the address and port to which the api would be. The user would define the ip address in the page, for example "192.168.1" and would have to pass this value to the provider, example "rest_usuario = ' link . I tried to use session but it does not work, localstorage works, but we need to restart the app again. This ip address is saved in a table in sqlite.
configuration.html
<form padding [formGroup]="configuracaoForm" (submit)="Enviar()" novalidate>
<ion-item>
<ion-label>Endereço IP</ion-label>
<ion-input type="text" [(ngModel)]="model.ip" formControlName="ip" placeholder="Endereço IP"></ion-input>
</ion-item>
<br>
configuracao.ts
Enviar() {
return this.dbProvider.getDB()
.then((db: SQLiteObject) => {
let sql = 'select * from configuracao where endereco_ip =?',
data = [this.model.ip];
return db.executeSql(sql, data)
.then((data: any) => {
if (data.rows.length > 0) {
let config: any[] = [];
for (var i = 0; i < data.rows.length; i++) {
var configuracao = data.rows.item(i);
config.push(configuracao);
localStorage.setItem("ip", this.model.ip)
rest.ts
insereUsuario() {
// this.endereco = window.sessionStorage.getItem('endereco');
return new Promise(resolve => {
this.http.get('http://' + localStorage.getItem("ip") + '/WebService/usuarios').subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}