我正在使用Angular7。我想在打字稿中获取并设置变量
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;
}
}
fLogin(user, pass) {
this.users.setUser=user;
}
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();
}
}
我希望在[[Login.Component.ts中设置值,并在Customer.Component.ts]中获取值如何运作或其他运作?
我正在使用Angular7。我想在打字稿中获取并设置变量。我的代码login.service.ts import'Injectable} from'@ angular / core'; @Injectable({{provedIn:'root'})导出类...