【发布时间】:2019-07-27 17:43:23
【问题描述】:
如何让这个函数返回真值或假值
autenticacion(){
let bool:boolean;
this.auth.autenticacion(this.auth.getToken()).subscribe(data=>{
if(data.data.token===this.auth.getToken()){
bool=true;
}else{
bool=false;
}
});
console.log(bool);
return bool;
}
this.autenticacion();
当我调用该函数时,我检查它是否使用控制台日志返回给我,但它返回一个未定义的值,有人知道如何让我返回 false 或 true
【问题讨论】:
-
你没有在这个函数中返回任何东西。
return不见了 -
1.在
console.log(...)之后添加return bool;。 2.你的if条件应该是data.data.token === this.auth.getToken()。 3.定义bool为bool: boolean; -
直接返回
bool -
如果我返回值仍然不返回任何内容
-
仍然显示未定义
标签: angular