Angular 2 login not working in safari and firefox

谁都会走 提交于 2020-01-06 07:05:34

问题


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

I get this error while trying to auth.

Now the code is working perfectly in chrome.

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

 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;
    }
  };

Any suggestions are welcomed.


回答1:


you need to upgrade the es6-shim.
check this -> https://www.npmjs.com/package/es6-shim




回答2:


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. 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.



来源:https://stackoverflow.com/questions/44901352/angular-2-login-not-working-in-safari-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!