title: How To Create Getter Setter In Angular
body: <p>I'm using Angular 7. I want to get and set variable in typescript</p>
  
  <h1>My Code login.service.ts</h1>
  
  <pre><code>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;
    }
  }
  </code></pre>
  
  <h1>And My Code In Login.Component.ts</h1>
  
  <pre><code>fLogin(user, pass) {
      this.users.setUser=user;
  }
  </code></pre>
  
  <h1>And My Code In Customer.Component.ts</h1>
  
  <pre><code>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();
    }
  }
  </code></pre>
  
  <blockquote>
    <p>I expect Set Value In <strong>Login.Component.ts</strong> And Get Value in <strong>Customer.Component.ts</strong></p>
    
    <p>How to it working or the other it working?</p>
  </blockquote>