Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { RequestOptions } from '@angular/http';
- @Injectable()
- export class SharedService {
- headers;
- url = 'http://localhost:8000/api/';
- constructor() {
- this.headers = '';
- }
- setHead(token: string){
- this.headers = new Headers({
- 'Authorization': 'Bearer ' + token,
- 'Content-Type': 'application/json'
- });
- }
- getHead(){
- return new RequestOptions({ headers: this.headers });
- }
- }
- import { SharedService } from './shared.service';
- @NgModule({
- bootstrap: [AppComponent],
- providers: [
- ...
- SharedService,
- ],
- export class AppModule {
- }
- constructor(
- private authService: NbAuthService,
- private sharedService: SharedService
- ) {
- this.authService.onTokenChange()
- .subscribe((token: NbAuthJWTToken) => {
- if(token.isValid()){
- this.sharedService.setHead(token.toString());
- }
- });
- }
- body : null
- headers : Headers
- __proto__ : Headers
- method : null
- params : undefined
- responseType : null
- search : (...)
- url : null
- withCredentials : null
- __proto__ : Object
Add Comment
Please, Sign In to add comment