0
firebase.service.tsangle2を使用してサーバーにfirebaseデバイストークンを送信
以下のコードは、私のangular2アプリケーションのfirebaseサービスです。設定ファイルはapp.module.tsにあります。私はデバイスのトークンIDをサーバーに送信したい。すべて正常に動作しますが、 "this.http.post(....)"の部分は機能しません。
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import * as firebase from 'firebase';
import { AuthService } from './auth.service';
import { ErrorModel } from '../_models/index';
@Injectable()
export class FirebaseService {
private messaging;
private errors = ErrorModel;
constructor(private authService:AuthService, private http:Http) {
this.messaging = firebase.messaging();
}
request_permission_for_notifications(){
this.messaging.requestPermission().then(()=>{
return firebase.messaging().getToken();
}).then(token=>{
if(this.authService.is_logged_in){
let options = this.authService.get_header();
let api_url = '/api/subscribe-device';
this.http.post(api_url,{token:token},options).map((response:Response)=>response.json());
}else{
console.log({success:false,message:this.errors.not_logged_in_error});
}
}).catch(err=>{
console.log('Unable to get permission to notify.', err);
});
}
}
コンソールのエラーを確認してください。 –
@PardeepJainコンソールにエラーはありません。 – Krisalay