问题
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:
- Run
npm install --save es6-shim - 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