插入全局变量的值不能在函数外部使用

时间:2018-11-27 11:04:22

标签: typescript logic

我正在尝试在Submit()中访问var Login的值,但无法这样做。可能是由于竞争条件。为什么我无法访问var Login的值?   代码:

class ABC {    
 Login : any;

 send(){
 this.preview.send().subscribe(
 (data =>{
  this.Login = data;
  console.log("This is the new list in send function",this.Login); //Printing value of this.Login
   })
 );

submit(value) {
 // let Log : any = this.Login_Object['login'];
  console.log('Inside submit function',this.Login);// Not printing value of this.Login
}
}

1 个答案:

答案 0 :(得分:0)

将this绑定到回调函数:

send(){
 this.preview.send().subscribe(
 (data =>{
  this.Login = data;
  console.log("This is the new list in send function",this.Login); //Printing value of this.Login
   }).bind(this)
 );