[英]Import Error on Stackblitz when trying to add component to module file
I'm using Stackblitz to practice angularJS and it's coming up with an error when I attempt to import a component in the app.module.ts file.我正在使用 Stackblitz 练习 angularJS,当我尝试在 app.module.ts 文件中导入组件时出现错误。
Import error, can't find file:
./heroes/heroes.component
app.module.ts app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
import { HeroesComponent } from './heroes/heroes.component';
https://stackblitz.com/edit/angular-akxx4e?file=src%2Fapp%2Fapp.module.ts https://stackblitz.com/edit/angular-akxx4e?file=src%2Fapp%2Fapp.module.ts
Update below Changes, because it's in different folder更新下面的更改,因为它在不同的文件夹中
import { HeroesComponent } from '../heroes/heroes.component';
This issue occurs due to component creation inside wrong location.由于在错误位置内创建组件,会出现此问题。 So
heroes component
should be created inside app
root.所以应该在
app
根目录中创建heroes component
。 This is the recommended answer.这是推荐的答案。
Correcting component's relative path is also works.更正组件的相对路径也是可行的。 But it is not the correct answer.
但这不是正确的答案。
import { HeroesComponent } from '../heroes/heroes.component';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.