简体   繁体   中英

how to refresh side menu in ionic / angular

after I do the login I can't get the username of the employee in the side menu and I don't know how to do it or what I'm missing the problem is like I explain in code with comments:

I want it to refresh the app.component.ts after I get the new data

please help me

here the app.component.ts file: As you can see here I can't get the name of the employee that login to the application

 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 } }

here the service.ts: here I pass the name of the employee after the login to send it to the 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; }

here some of login.ts:As you can see in the login.ts I console.log I get the value of the username but I can't get this data in the 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 });

You have single page application and can't to refresh page, but you can use Observbles for subscribe changes. I think is better to have Subject<string> and subscribe that. in login you can Next that, in this solution in all of your app, you can refresh data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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