我有一个包含模块的文件,如下所示
ROOT/数据库/models.ts
module Model {
export interface Inbox {
title: string;
msg: string;
}
export interface User{
Id: string;
Name: string;
}
}
我想从主文件访问接口。看看我尝试了什么
ROOT/pages/main.ts
import { Model} from '../database/models'; //<-- here is my problem
export class WorkerPostbidPage {
myinbox:Model.Inbox; // <-- And I want to call it as this
TestMethod() {
this.myinbox = {
title:"new msg",
msg:"you have an alert"
}
}
}
但是当我将外部模型文件内容复制到 main.ts 中时,如下所示它工作正常
module Model {
export interface Inbox {
title: string;
msg: string;
}
export interface User{
Id: string;
Name: string;
}
}
export class WorkerPostbidPage {
myinbox:Model.Inbox; // <-- And I want to call it as this
TestMethod() {
this.myinbox = {
title:"new msg",
msg:"you have an alert"
}
}
}
我想我可能做错了什么,或者我错过了某些部分
您应该重写 model.ts 文件,使其符合 ES6 模块。
export interface Inbox {
title: string;
msg: string;
}
export interface User{
Id: string;
Name: string;
}
然后你应该能够像这样导入它们。
import { Inbox } from '../database/models';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句