【问题标题】:how to refresh side menu in ionic / angular如何刷新离子/角度的侧边菜单
【发布时间】:2021-04-24 04:39:15
【问题描述】:

登录后,我无法在侧边菜单中获取员工的用户名,我不知道该怎么做 或者我缺少的问题就像我用 cmets 在代码中解释的那样:

我希望它在获得新数据后刷新 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 
      
    });

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

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

    【讨论】:

    • 你能给我一个阅读它的来源或其他一些提示
    • 对于您的问题,BehaviorSubject 是不错的选择。在这个link你可以学习它。
    • 这对我很有用 link 这个视频帮了我很多忙:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2020-08-14
    • 2017-02-21
    • 1970-01-01
    相关资源
    最近更新 更多