I'm using Angular 7. I want to get and set variable in typescript
My Code login.service.ts
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LoginService {
public username:string;
public token:string;
public fullname:string;
constructor() { }
set setUser(val: string){
this.username = val;
}
set setToken(val:string){
this.token=val;
}
set setFullName(val:string){
this.fullname=val;
}
get getUser():string{
return this.username;
}
get getToken():string{
return this.token;
}
get getFullName():string{
return this.fullname;
}
}
And My Code In Login.Component.ts
fLogin(user, pass) {
this.users.setUser=user;
}
And My Code In Customer.Component.ts
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { Http, Headers } from "@angular/http";
import {LoginService} from "../login.service"
import { NgLocalization } from '@angular/common';
@Component({
selector: 'app-customers',
templateUrl: './customers.component.html',
styleUrls: ['./customers.component.css']
})
export class CustomersComponent implements OnInit {
constructor(public user:LoginService) {
}
loadData() {
console.log(this.user.getUser)
}
ngOnInit() {
this.loadData();
}
}
I expect Set Value In Login.Component.ts And Get Value in Customer.Component.ts
How to it working or the other it working?