本文整理汇总了TypeScript中ng2-cookies/ng2-cookies.Cookie.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Cookie.get方法的具体用法?TypeScript Cookie.get怎么用?TypeScript Cookie.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ng2-cookies/ng2-cookies.Cookie
的用法示例。
在下文中一共展示了Cookie.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// get the token from a service
const authHeader = `Bearer ${Cookie.get('token')}`;
const authReq = req.clone({setHeaders: {Authorization: authHeader}});
if(authHeader)
return next.handle(authReq);
else
return next.handle(req);
}
示例2: request
request(method: METHOD, url: string, body?: any) {
let token = Cookie.get('auth-token');
var headers = new Headers();
headers.append('Authorization', 'Bearer ' + token);
switch (method) {
case METHOD.GET:
return this.get(url, headers);
case METHOD.PUT:
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.put(url, headers, body);
case METHOD.DELETE:
return this.delete(url, headers);
}
}
示例3: appInjector
export const isLoggedIn = (next: ComponentInstruction, previous: ComponentInstruction) => {
let injector: Injector = appInjector(); // get the stored reference to the injector
let auth: Auth = injector.get(Auth);
let router: Router = injector.get(Router);
let myCookie = JSON.parse(Cookie.get('loginRecord'));
console.log(myCookie)
// return a boolean or a promise that resolves a boolean
return new Promise((resolve) => {
if(myCookie != null){
if (myCookie.loginIn) {
resolve(true);
} else {
router.navigate(['/Login']);
resolve(false);
}
}else{
router.navigate(['/Login']);
resolve(false);
}
});
};
示例4: ngOnInit
ngOnInit() {
this.user = this.store.select('userReducer');
const token = Cookie.get('KycTokenSession');
if (token && token !== '') {
const data = this.apiService.validateToken(token);
if (data.error) {
this.apiService.signoutProccess();
this.router.navigate(['/signin']);
} else {
this.session = data;
let user = Object.assign(new User(), this.session.user);
user.token = this.session.token;
user.role = user.role.id;
user.isLogged = true;
this.store.dispatch({type: SET_VALIDATE_TOKEN, payload: true});
this.store.dispatch({type: SET_USER, payload: user});
}
} else {
this.store.dispatch({type: SET_VALIDATE_TOKEN, payload: true});
}
const route = window.location.href.split('/');
}
示例5: createAuthorizationHeader
createAuthorizationHeader(headers:Headers) {
let basicAuthCredentials = Cookie.get('basicAuthCredentials');
if (basicAuthCredentials) {
headers.append('Authorization', 'Basic ' + basicAuthCredentials);
}
}
示例6: platformBrowserDynamic
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppSettings} from './app.settings';
import { AppModule } from './app.module';
import { Cookie } from 'ng2-cookies/ng2-cookies';
import { TranslateService } from 'ng2-translate/ng2-translate';
if(!Cookie.get('lang')){
AppSettings._language = navigator.language;
Cookie.set('lang', AppSettings._language);
}
else
{
AppSettings._language = Cookie.get('lang');
}
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);