我如何将 'mytoki' 的值从我的模态组件发送到其父级?
我不确定是否应该创建另一个 EventEmitter 或服务。有什么建议么 ?
@Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.css']
})
export class ModalComponent implements OnInit {
@Output()
toHide = new EventEmitter();
private usrname;
private pswd;
private visible: string;
private mytoki;
constructor(private loginservice: LoginService) { }
ngOnInit() {
}
connect(usrname, pswd) {
this.loginservice.getUserLogin(this.usrname, this.pswd).subscribe(
response => {
this.mytoki = response.headers.get('Authorization');
sessionStorage.setItem('token', this.mytoki);
console.log('Connected');
}, err => {
// TODO
// login errors
// put token into nav component
}, () => {
this.visible = 'hide';
this.toHide.emit(this.visible);
this.usrname = '';
this.pswd = '';
}
);
}
}