I am using Angular with my IONIC application, but I have a problem.
Create a service to request data to my API, everything works fine on my computer it does it great. But when compiling for android, when I install the APK and test my application the service does not work. What should I do? I’ve been searching but I can’t find the solution.
Now that same service is loaded in another component and if it works, what is happening because I have no idea.
My component where I try to load the service but it works on PC but not on mobile device:
"Usuario" It is my service where I establish the connection with my API.
"datausr" Where I save the data that the API returns, for example “Nombre”.
import { Component, OnInit } from '@angular/core';
import {ModalController} from '@ionic/angular';
import {Usuario} from '../service/user.service';
import { TokenService } from '../service/token.service';
import {EditperfilComponent} from '../editperfil/editperfil.component';
@Component({
selector: 'app-perfil',
templateUrl: './perfil.component.html',
styleUrls: ['./perfil.component.scss'],
providers:[Usuario]
})
export class PerfilComponent implements OnInit {
usuario:any;
datausr:any;
constructor(
public user:Usuario,
public tokenService:TokenService,
private modalController: ModalController
) { }
ngOnInit() {
this.loaddata();
}
loaddata(){
this.usuario =this.tokenService.getUserName();
this.user.getuserdetail(this.usuario).subscribe(
result =>{
if (result.Mensaje == 'ok') {
this.datausr=result.Data;
}else{
}
},
error=>{
console.log(<any>error);
}
);
}
}
Now when I try to print that value in my ionic view, on PC it works normal, but on my device it does not load or does not execute the function “loaddata ()” or it may be that what it does not execute is "this.user.getuserdetail ( this.user) .subscribe () "
Can someone tell me what is happening or is it something I need to know or do before.
2 posts - 2 participants