compiler-errors - Ionic2/Angular2 语法错误

标签 compiler-errors angular ionic2

我正在尝试在 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/

相关文章:

angular - 将 BehaviorSubject 值作为参数传递

java - getdocumentBase() 上出现错误 "Cannot find symbol "

visual-studio-2015 - 无法在 Visual Studio 2015 中恢复作用域 Angular 2 包

gcc - 奇怪的编译错误

angular - 使用 DirectiveResolver 更改 @Component 元数据

angular - 你能在 Angular 2(使用 Typescript)中返回一个 observable 作为 promise 吗?

typescript - 如何在 typescript 中导入类型定义?

angular - 带有 Angular/Ionic : How do I find the redirect_uri? 的 Google OAuth 客户端

java - 注释代码在 Java 中给出编译错误?

java - 预计出现编译错误 <identifier>