我正在尝试在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
}
}
答案 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)
);