错误TS2322:类型'string'无法分配给类型'Type <any>'。在角度7

时间:2018-10-26 05:38:22

标签: angular typescript angular7

我正在使用angular7,并为管理员进行路由,但其给定错误“字符串无法分配给类型”,谁能知道这是什么错误,我该如何解决?

错误截图:-

enter image description here

admin.routing.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { adminComponent } from './admin.component';

const routes:  Routes =[
    {
        path: 'admin',
        component:adminComponent,
        children: [
            {path: '', component: 'loginComponent', pathMatch: 'full'},
            {path: 'dashboard', component: 'dashboardComponent'}
            //{path: 'login', component: 'loginComponent'}
        ]
    }
];

export const adminComponents = [
    adminComponent
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})

export class adminRouterModule{

}

2 个答案:

答案 0 :(得分:1)

component: loginComponent删除

{path: '', component: loginComponent, pathMatch: 'full'},
{path: 'dashboard', component: dashboardComponent}

答案 1 :(得分:0)

您的组件不应为 string ,它是 component 名称

更改

发件人

  {path: 'dashboard', component: 'dashboardComponent'}

收件人

  {path: 'dashboard', component: dashboardComponent}