我在身份验证后在控制台中出错。重新加载页面后,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() {
}
}