【发布时间】:2016-02-20 14:20:34
【问题描述】:
我正在尝试从我的 api 返回信息,但我不明白如何正确使用订阅。使用数组,我从我的服务返回一个空数组,并在获取值时将值推送到其中。
如何正确返回 app-component ts 中的单个值变量。现在如果我做一个alert(JSON.stringify(authenticated)) 它只会给我{"_isUnsubscribed":false,"_subscriptions":[{"isUnsubscribed":false}]}
应用组件 ts
checkAuthentication(){
var authenticated = this._authService.getAuthenication();
}
认证服务
getAuthenication() {
return this._http.get('auth.php').subscribe(res => {
if (res.json().authenticated === true){
return true;
}
return false;
});
}
auth.php
<?
session_start();
$authenticated = ( isset($_SESSION["authenticated"]) ? true : false );
$post_data = json_encode(array(authenticated => $authenticated));
echo $post_data;
?>
【问题讨论】:
标签: javascript typescript angular