5
私のAPIから情報を返そうとしていますが、正しく購読する方法を理解できません。配列を使用して、私のサービスから空の配列を返し、値を取得します。TypeScript Angular 2 Responses Subscription
app-component tsで1つの値の変数を正しく返すにはどうすればよいですか。今私は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を購読していますが、それに関するドキュメントはありますか? – ClickThisNick
申し訳ありません、変更を忘れました –
認証されたものは.subscribe(value => this.authenticated = authenticated)で参照されます。それはapp.component上にある変数にありますか、それとも価値のあるプロパティですか?私はマップ内でtrueまたはfalseを返しています。res.json()を返すべきですか? – ClickThisNick