I am trying to return information from my api, but I do not understand how to use the subscription correctly. With an array, I return an empty array from my service and paste the values into it when I receive them.
How to correctly return only one value variable in app-component ts. Right now, if I do an alert(JSON.stringify(authenticated)) , it just gives me {"_isUnsubscribed":false,"_subscriptions":[{"isUnsubscribed":false}]}
app-component ts
checkAuthentication(){ var authenticated = this._authService.getAuthenication(); }
Authentication service
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; ?>
source share