ts1206 decorators are not valid here, Angular 2

前端 未结 3 1122
半阙折子戏
半阙折子戏 2021-02-11 11:56

I started to program Angular 2 and I stuck with an error:

ts1206 decorators are not valid here

@Component({   //  ts1206 de         


        
3条回答
  •  广开言路
    2021-02-11 12:35

    This error came to me when I used angular routing and defined routes after @NgModule decorator.

    We need to define routes or any other decorater before the @NgModule decorator.

    const appRoutes: Routes = [    // define this before @NgModule 
     { path: '',
       redirectTo: '/home',
       pathMatch: 'full'
     },
     { path: 'home', component: HomeComponent },
    ];
    
    
    @NgModule({            // This Decorator should be just before an exported class 
    declarations: [
     AppComponent,
     HeaderComponent,
     HomeComponent
    ],
    imports: [
     BrowserModule,
     RouterModule.forRoot(
       appRoutes,
       { enableTracing: true } // <-- debugging purposes only
     )
    ],
    providers: [],
    bootstrap: [AppComponent]
    })
    export class AppModule { }
    

提交回复
热议问题