Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class LoginComponent implements OnInit {
- constructor(private fb: FormBuilder, private loginService: LoginService) { }
- submitError = false; // set "true" to show error
- onSubmit(){
- this.submitError = false;
- this.submitErrorText = "";
- this.model = this.loginForm.value;
- this.loginService.authenticate(this.model.login_id, this.model.password)
- .then(res => {
- if(res.status == 404){
- this.submitError = true;
- }
- else{
- // do something
- }
- }).catch(function(err: any){
- this.submitError = true; // Unhandled promise rejection TypeError: Cannot set property 'submitError' of undefined
- });
- }
- import {Injectable} from '@angular/core';
- import { Http } from '@angular/http';
- import 'rxjs/add/operator/toPromise';
- @Injectable()
- export class LoginService{
- private auth_url = "/login/api/auth";
- constructor(private http: Http){};
- authenticate(username: String, pass: String): Promise<any>{
- return this.http.post(this.auth_url, {username: username,pass: pass})
- .toPromise()
- .then(response => response.json())
- .catch(this.handleError);
- }
- private handleError(error: any): Promise<any>{
- return Promise.reject(error.message || error);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement