Angular 2登录无法在Safari和Firefox中使用 [英] Angular 2 login not working in safari and firefox

查看:109
本文介绍了Angular 2登录无法在Safari和Firefox中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的应用程序的登录部分无法在safari和firefox上运行.

For some reason the login part of my application is not working on safari and firefox.

我在尝试进行身份验证时收到此错误.

I get this error while trying to auth.

现在代码在chrome中可以正常工作了.

Now the code is working perfectly in chrome.

登录Service.ts

Signin Service.ts

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Http, Headers, RequestOptions } from '@angular/http'; 

import { HttpWrapper } from '../../../shared/services/http-wrapper.service';
import { SERVER_URL } from '../../../shared/config/config';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

@Injectable()
export class SigninService {

  constructor(
    private http_native: Http,
    private http: HttpWrapper
  ) { };

  public login(user: { email: string, password: string }): Observable<any> {
    let headers = new Headers({ 'Content-Type': 'application/json' });
    headers.append('Accept', 'application/json;q=0.9,*/*;q=0.8')

    let options = new RequestOptions({ headers: headers });
    return this.http_native.post(`${SERVER_URL}users/login`, JSON.stringify(user), options)
      .catch((error: any) => {
        return Observable.throw(error);
      })
      .map((response: Response) => {
        return response.json();
      })
  };

SinginComponent.ts

SinginComponent.ts

 public login($event): void {
    $event.preventDefault();

    if (this.signinForm.valid) {
      this.signinFormIsValid = true;
      let { email, password } = this.signinForm.value;

      this.signinService.login({ email, password })
        .subscribe((response: any) => {
          console.log('response', response);
          sessionStorage.setItem('user', JSON.stringify(response));
          this.loginDispatcherService.setUser(response);

          this.availableParties = response.associatedPartyIds;
          this.tokenId = response.authenticationTokenId;
          this.stepOne = false;
          this.stepTwo = true;

        });
    } else {
      this.signinFormIsValid = false;
    }
  };

欢迎任何建议.

推荐答案

Safari和Firefox需要es6-shim,如

Safari and Firefox require the es6-shim as described in the Mandatory Polyfills section of the docs.

请按照以下步骤解决您的问题:

Follow these steps to fix your issue:

  1. 运行npm install --save es6-shim
  2. 编辑您的polyfills.ts文件,在新行上添加import 'es6-shim'.
  1. Run npm install --save es6-shim
  2. Edit your polyfills.ts file, adding import 'es6-shim' on a new line.

构建您的应用程序,它现在应该可以正常工作.

Build your application and it should now work.

这篇关于Angular 2登录无法在Safari和Firefox中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆