Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Api 身份验证后出现角度2错误-找不到要加载的主出口_Api_Angular_Authentication_Angular2 Routing - Fatal编程技术网

Api 身份验证后出现角度2错误-找不到要加载的主出口

Api 身份验证后出现角度2错误-找不到要加载的主出口,api,angular,authentication,angular2-routing,Api,Angular,Authentication,Angular2 Routing,身份验证后控制台中出现错误。重新加载页面后,CreateChartComponent页面开始工作。验证过程中刚刚发生错误 Uncaught (in promise): Error: Cannot find primary outlet to load 'CreateChartComponent' 这是登录功能 login(event, username, password): void { event.preventDefault(); this.authService.login(usern

身份验证后控制台中出现错误。重新加载页面后,CreateChartComponent页面开始工作。验证过程中刚刚发生错误

Uncaught (in promise): Error: Cannot find primary outlet to load 'CreateChartComponent'
这是登录功能

login(event, username, password): void {
event.preventDefault();
this.authService.login(username, password).subscribe(
  res => {
    this.router.navigate(['drawing']);
  },
  err => {
    // todo: handle error with a  lable
    console.log(err);

    if (err.ok === false) {
      this.errorMessage = 'Error logging in.';
    }
  });
}
}
传统信息:

我发送清晰模式的代码,我得到相同的问题。 这是路由器代码:

 // Import our dependencies
    import { Routes } from '@angular/router';
    import { AppComponent } from './app.component';
    import { LoginComponent } from './home/login/login.component';
    import { CreateChartComponent } from './home/drawing/create-chart.component';

    import { AuthGuard } from './auth.guard';

    // Define which component should be loaded based on the current URL
    export const routes: Routes = [
        { path: '', component: CreateChartComponent, pathMatch: 'full', canActivate: [AuthGuard] },
        { path: 'login', component: LoginComponent },
        { path: 'drawing', component: CreateChartComponent, canActivate: [AuthGuard] },

    ];
以及它的create-chart.component.ts

    import {
      Component,
      OnInit,

    } from '@angular/core';

    @Component({
      selector: 'np-chart-create',
      templateUrl: './create-chart.component.html',
      styleUrls: ['./create-chart.component.css']
    })

    export class CreateChartComponent implements OnInit {
      ngOnInit() {
      }
    }

共享您的CreateChartComponent、路由器文件和App.component.ts的代码,其中定义了您的路由器出口。您的路由怎么了,似乎有点奇怪。我看到在访问
CreateChartComponent
之前需要登录,所以路径
'
不应该引用登录组件吗?