GET http:// localhost:4200 / api / user / 404(Not Found)angular 2

时间:2017-07-25 18:05:39

标签: angular typescript angular-routing angular-services discogs-api

当我尝试登录到我的应用程序时出现此错误但是我遇到了包含404(未找到)的问题...我会在代码中添加一些行和错误的图像.....请帮我解决这个问题。

@Injectable()
export class AuthGuard implements CanActivateChild {
  loggedInUser: string;

  constructor( private localStorage: LocalStorageService, private router: Router ) {
    this.loggedInUser = localStorage.get('discogs-user') as string;
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    if (this.loggedInUser) {
      return true;
    }

    this.router.navigate(['/login']);
  }
}

这是带有subscribe

的login.component.ts
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';

import { Observable } from 'rxjs/Observable';

import { MdlSnackbarService } from 'angular2-mdl';

import * as fromRoot from '../../reducers';
import * as user from '../../actions/user';

import { DiscogsUser, UserLogin } from '../../models';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html'
})
export class LoginComponent {
  user$: Observable<DiscogsUser>;

  login(login: UserLogin) {
    if (!login.username) {
      this.store.dispatch(new user.LoginFailedAction('You must enter a username'));
      return;
    }

    this.store.dispatch(new user.LoginAction(login));
    this.router.navigate(['/']);
  }

  private _showError(message: string) {
    this.mdlSnackbarService.showSnackbar({
      message: message,
      action: {
        handler: () => { },
        text: 'OK'
      }
    });
  }

  constructor(private store: Store<fromRoot.State>, private router: Router, private mdlSnackbarService: MdlSnackbarService) {
      this.user$ = store.select(fromRoot.getUser);

      store.select(fromRoot.getLoginFailed)
        .subscribe(error => {
          if (error) {
            this._showError(error);
          }
        });

    }
}

这是错误的图像

error

0 个答案:

没有答案