Good day. Studying Angular2. Met with incomprehensible strangeness. Example from the tutorial:

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; import {HeroDetailComponent} from './hero-detail.component'; import {HeroService} from './hero.service'; import {BackendService} from './backend.service'; import {Logger} from './logger.service'; import {HeroesComponent} from './heroes.component'; import {RouterModule, Routes} from '@angular/router'; const appRoutes: Routes = [ { path: 'heroes', component: HeroesComponent } ]; @NgModule({ declarations: [ AppComponent, HeroDetailComponent, HeroesComponent, ], imports: [ BrowserModule, FormsModule, HttpModule, RouterModule.forRoot([ appRoutes ]) ], providers: [HeroService, BackendService, Logger], bootstrap: [AppComponent] }) export class AppModule { } 

We have an error:

Unhandled Promise rejection: Invalid configuration of route '': Array cannot be specified; Zone:; Task: Promise.then; Value: Error: Invalid configuration of route '': Array cannot be specified Stack-trace: validateNode @ http: // localhost: 4200 / vendor.bundle.js: 65001: 15 [angular] ....

Practically the same (without the module import section, for short)

 @NgModule({ declarations: [ AppComponent, HeroDetailComponent, HeroesComponent, ], imports: [ BrowserModule, FormsModule, HttpModule, RouterModule.forRoot([ { path: 'heroes', component: HeroesComponent } ]) ], providers: [HeroService, BackendService, Logger], bootstrap: [AppComponent] }) export class AppModule { } 

Those. from const transferred directly to the body

Everything works great! I do not understand.

    1 answer 1

    In the first variant (where is a constant) you have a path already in the array, so the array is then obtained in the array. Accordingly, in the second embodiment, just an array. Remove one of the arrays (square brackets) in the declaration of a constant, for example.