我在这个地址做angular2教程:https://angular.io/docs/ts/latest/tutorial/toh-pt3.html我把hero接口放在app文件夹下的一个文件中,在控制台中我有一个错误:

app/app.component.ts(2,20): error TS2306: File 'app/hero.ts' is not a module.
[0] app/hero-detail.component.ts(2,20): error TS2306: File 'app/hero.ts' is not a module.

如果我把我的界面文件放在hero文件夹中,错误就会消失,this is not mentioned in the documentation, what's wrong with my import

我在app.components.tshero-detail.component.ts中的import指令(在组件文件的开头):

import {Component} from 'angular2/core';

import {Hero} from './hero';

Must I replace我的进口指令:import {Hero} from './'; or simply put the code in a hero folder

推荐答案

try 重新启动编写代码的编辑器(VS code或Sublime).

当您从编辑器外部添加一个新类或继续运行您的Angular CLI‘ng SERVER’时,就会发生这种情况.实际上,您的编辑器或"ng serve"命令可能无法找到新创建的文件.

Angular相关问答推荐

文件阅读器未正确给出某些CSV文件的结果

如何跨不同组件使用ng模板

NGX- colored颜色 Select 器安装出错

确保我的角库S服务构建提供独立的友好提供功能

Angular 16 Auth Guard在具有0的服务时给出Null Injector错误;httpclient;被注入

如何让 ag-Grid 事件读取私有方法?

具有两个订阅方法的 Angular 16 takeUntilDestroyed 运算符

Angular 升级后 RXJS SwitchMap 无法与解析器一起正常工作

PrimeNG:如何以编程方式更改分页器中的选定页面?

Angular 13 - 使用 PUT 时出现 400 错误(错误请求)

ng14中具有强类型表单的FormBuilder

在更改检测之前调用创建的间谍

angular 13 ng 构建库失败(ivy部分编译模式)

使用directive指令将类添加到host元素中

如何在angular material中使用输入类型文件

如何在 Angular 2 中正确设置 Http 请求标头

Angular 5 测试:如何获取对子组件的引用

Angular 2 router.navigate

BrowserAnimationsModule 和 NoopAnimationsModule 有什么区别?

在angular-cli中创建模块时生成路由模块