需要修复模块中找不到的错误-Angular

时间:2019-05-31 02:32:57

标签: javascript angular typescript

我正在练习angular,但是在编译我的代码时收到此错误:

Module not found: Error: Can't resolve './app.component.css' in 'D:\hello-world-app\src\app'
i 「wdm」: Failed to compile.

我的app.component.html

<h1>Angular</h1>
<courses></courses>

我的courses.component.ts

// tslint:disable-next-line: import-spacing
import{Component} from '@angular/core';


@Component({
  selector: 'courses', //<courses>
  template: '<h2>Courses</h2>'
})
export class CoursesComponent {

}

我的app.component.ts


import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'hello-world-app';
}

我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { CoursesComponent } from './courses.component';

@NgModule({
  declarations: [
    AppComponent,
    CoursesComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

1 个答案:

答案 0 :(得分:1)

Angular未能找到( resolve )文件,正如错误所指出的那样。为了解决该错误,您需要添加文件或删除行styleUrls: ['./app.component.css']

如果您不想避免文件引用并且正在使用angular cli(如果不是,则应该这样做),可以在生成组件时使用--inlineStyle=true。当然,如果您使用的是角度cli,则在生成组件时应该已经创建了css文件

可能是您复制粘贴了某些内容,或者是错误地删除了该文件。无论哪种方式,当Angular找不到您要引用的内容时,它总是会抱怨。 (与其他编程框架/系统/语言非常相似)