【发布时间】: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
});
【问题讨论】: