我正在尝试在 Ionic2/Angular2 中开发应用程序
我想声明一个简单的模型并得到编译错误
如下。请帮忙指出编译错误的原因。
模型1:global.data.ts
import {Injectable} from "angular2/core";
@Injectable
export class GDService{
private _newpost:string;
private _allpost:string;
}
Compilation error:
import {Injectable} from "angular2/core";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
SyntaxError: global.data.js: Unexpected token (5:9) while parsing file:
模型2:job.mdl.ts
export class Job{
constructor(
id:number,
category:string,
type:string,
details:string
){
}
}
Compilation error:
export class Job{
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
最佳答案
编辑:
它可能与您的 tsconfig 文件有关,请确保您在那里定义了一个模块,例如:
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
关于compiler-errors - Ionic2/Angular2 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37371686/