首页 > 解决方案 > `not a module` - 接口分配错误

问题描述

我正在尝试将界面添加到我的应用程序组件中。得到错误interface.ts is not a module- hot 来解决这个问题。

我的 appComponent.ts:

import { Component } from "@angular/core";
import { Name } from "./interface";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent {
  name:Name = "CodeSandbox";
}

我的界面.ts:

export interface Name {
  name: string;
}

我的代码有什么问题?谁能帮我?

标签: typescriptangular6

解决方案


您的接口文件名必须与您的接口名称匹配。所以你必须将你的接口文件重命名为我的 Name.ts:

export interface Name {
  name: string;
}

import { Name } from "./Name ";

推荐阅读