在这里我用symfony开发了我的api rest,现在我用ionic开发了移动应用程序,并完成了登录和注册阶段。现在我正在寻找一种方法来访问已连接用户的数据知道我使用我的api rest的网址并且在本地主机工作,因此能够在html页面中显示其数据。 我做了身份验证服务,并根据用户类型将用户定向到我的页面。
对于我来说,我想检索刚刚登录的患者用户的数据,我想在其html页面上获取其信息。
身份验证服务
export class AuthenticationService {
constructor(private httpService: HttpService,private router: Router,) {
login(postData: any): Observable<any> {
return this.httpService.post('login',postData);
}
signup(postData: any): Observable<any> {
return this.httpService.post('signup',postData);
}
logout() {
localStorage.removeItem('id_token');
this.router.navigate(['/home']);
}
}
Http服务
export class HttpService {
private API_URL = 'http://127.0.0.1:8000/';
constructor(private http: HttpClient) { }
apiBase = this.API_URL + 'api/login';
post( serviceName: any,data: any) {
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
const options = { headers,withCredintials: false };
return this.http.post(this.apiBase,JSON.stringify(data),options);
} }
患者仪表板ts
export class PatientDashboardPage implements OnInit {
data: any;
bords: any;
public authUser: any;
constructor(private menu: MenuController,private auth:
AuthenticationService) {
this.bords = [
{
title: 'Tableau de bord',icon: 'desktop',path: '/patient-dashboard/bord',},{
title: 'Mes rendez-vous',icon: 'calendar',path: '/booking',{
title: 'Mon Profil',icon: 'clipboard',path: '/profil',{
title: 'Feedback',icon: 'chatboxes',path: '/feedback',}
];
}
ngOnInit() {
}
showDetail(arg: any) {
this.router.navigateByUrl(arg);
}
}
患者仪表板html
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title style="color: darkgreen">Welcome to Doctix </ion-title>
</ion-toolbar>
</ion-header>
<ion-content fullscreen >
<ion-list style="padding-top: 0.5em">
<ion-item button *ngFor="let bord of bords"
(click)="showDetail(bord.path)"style="padding-top: 4em">
<ion-icon style="color: darkgreen" slot="start" name="{{bord.icon}}" ></ion-icon>
<ion-label>
<h3>{{bord.title}}</h3>
</ion-label>
</ion-item>
</ion-list>
</ion-content>
谢谢