Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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
Html 在Angular中添加规则失败_Html_Angular - Fatal编程技术网

Html 在Angular中添加规则失败

Html 在Angular中添加规则失败,html,angular,Html,Angular,我有一个问题,添加简单的规则到角度。我遵循guide(),我的代码如下所示: app.module.ts import {Routes, RouterModule} from "@angular/router"; const routes: Routes = [ { path: '', component: HomeComponent }, ]; @NgModule({ declarations: [ AppComponent, HeaderComponent,

我有一个问题,添加简单的规则到角度。我遵循guide(),我的代码如下所示:

app.module.ts

import {Routes, RouterModule} from "@angular/router";


const routes: Routes = [
  { path: '', component: HomeComponent },
];

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    ContentComponent,
    FooterComponent,
    CuriositiesComponent,
    HomeComponent,
    RouterModule.forRoot(routes, {useHash: true}),
  ],
  imports: [
    BrowserModule,
    SwiperModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
不幸的是,在编译过程中出现了一些错误,我不知道问题出在哪里:

ERROR in src/app/app.module.ts(20,11): error TS2345: Argument of type '{ declarations: (ModuleWithProviders | typeof HomeComponent | typeof AppComponent)[]; imports: (t...' is not assignable to parameter of type 'NgModule'.
  Types of property 'declarations' are incompatible.
    Type '(ModuleWithProviders | typeof HomeComponent | typeof AppComponent)[]' is not assignable to type '(any[] | Type<any>)[]'.
      Type 'ModuleWithProviders | typeof HomeComponent | typeof AppComponent' is not assignable to type 'any[] | Type<any>'.
        Type 'ModuleWithProviders' is not assignable to type 'any[] | Type<any>'.
          Type 'ModuleWithProviders' is not assignable to type 'Type<any>'.
            Property 'apply' is missing in type 'ModuleWithProviders'.
src/app/app.module.ts(20,11)中的错误:错误TS2345:类型为“{declarations:(ModuleWithProviders | typeof HomeComponent | typeof AppComponent)[];导入:(t..”不可分配给类型为“NgModule”的参数。
属性“声明”的类型不兼容。
类型“”(ModuleWithProviders | typeof HomeComponent | typeof AppComponent)[]”不可分配给类型“”(任何[]|类型)[]”。
类型“ModuleWithProviders | typeof HomeComponent | typeof AppComponent”不可分配给类型“any[]| Type”。
类型“ModuleWithProviders”不可分配给类型“any[]| Type”。
类型“ModuleWithProviders”不可分配给类型“Type”。
类型“ModuleWithProviders”中缺少属性“apply”。

声明
NgModule的元数据选项装饰器只持有
组件
管道
指令
。不能将
路由模块
放在
声明
选项内。应该放在
导入
选项内

imports: [
   //Removed RouterModule from declarations and shifted inside import. 
   RouterModule.forRoot(routes, {useHash: true}),
   BrowserModule,
   SwiperModule
],