繁体   English   中英

如何在 ionic / angular 中刷新侧边菜单

[英]how to refresh side menu in ionic / angular

登录后,我无法在侧面菜单中获取员工的用户名,我不知道该怎么做或我遗漏了什么问题就像我在代码中用注释解释:

我希望它在获得新数据后刷新 app.component.ts

请帮我

这里是 app.component.ts 文件:正如您在此处看到的,我无法获取登录到应用程序的员工的姓名

 import { Component, OnInit } from '@angular/core'; import { LoginserviceService } from '../app/services/serviceLogin/loginservice.service'; @Component({ selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.scss'], }) export class AppComponent implements OnInit { name: string; responsable: boolean; is_Responsable_Or_Agent: string; constructor(private loginser: LoginserviceService) {} // this is the login service ngOnInit() { this.name = this.loginser.getArName(); console.log(this.name)// when i console this name i got nothing } }

这里是service.ts:这里我把登录后员工的名字传给app.component.ts

 private ArName: string = ''; // this is the name of the employee constructor(private http: HttpClient) {} setArName(name) { // this method to set the value of the name of the user after the login this.ArName = name; } getArName() { // this method is to get the name of the user after the login return this.ArName; }

这里有一些 login.ts:正如你在 login.ts 中看到的那样,我在console.log中获得了用户名的值,但我无法在 app.component.ts 中获得这些数据

 logForm() { console.log(this.Form.value.employeeN); this.Loginser.getdata(this.Form.value.DECAFFE).subscribe((res) => { console.log(res); this.employee = res as Drafbies;//here the information of the user this.Loginser.setArName(this.employee.AR_DELAFFE);//here the name of the user console.log('name is ' + this.Loginser.getArName());// when i console.log this line I get the name of the employee login // but I can't get this information on app.componnt });

您有单页应用程序,无法刷新页面,但您可以使用 Observbles 订阅更改。 我认为最好有Subject<string>并订阅它。 在登录中,您可以Next ,在此解决方案中您的所有应用程序中,您可以刷新数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM