找不到“ AppModule” Angular 6.1.0的NgModule元数据中的错误

时间:2018-09-26 02:46:51

标签: angular angular6

app.module.ts 这是AppModule的代码

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { PostListComponent } from './post/post-list.component';
import {PostService} from './post/post.service';
import { HomepageComponent } from './homepage/homepage.component';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
  declarations: [
    AppComponent,
    PostListComponent,
    HomepageComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule

  ],
  providers: [
    PostService
  ]
  bootstrap: [AppComponent]
});
export class AppModule { }

app-routing.module.ts

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {ProjectListComponent} from '.post/post-list.component';
import {HomePagecomponent} from './homepage/homepage.component';
const routes: Routes =  [
  { path: '', redirectTo: '/home', paathMatch: 'full' },
  { path: 'home', component: HomePagecomponent },
  { path: 'posts', component: PostListComponent},
  //{ path: 'post/new', component: PostNewComponent},
  //{ path: 'post/show', component: PostShowComponent},
]
@NgModule({
  imports: [ RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule{

}

根据需要注释其他代码以帮助我,您也可以共享教程和与主题相关的其他数据。谢谢 main.ts文件

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

在这里共享了我的main.ts文件。

1 个答案:

答案 0 :(得分:0)

尝试一下:

1),然后擦除 node_modules 文件夹:

npm cache clean --force
npm install
npm install --save-dev @angular/cli@latest