离子2语法错误在编译时打字稿 [英] Ionic 2 Syntax Error While Compiling TypeScript

查看:151
本文介绍了离子2语法错误在编译时打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下教程这里我得到的地步,我得到在编译我的打字稿code语法错误。

以下是错误:


  

/app/pages/list/list.js模块构建失败:语法错误:
  /focus/projects/ionic-todo/app/pages/list/list.js:意外的令牌
  (10:17)8 | 9 |出口类末页{


  
  

    

10 |构造函数(NAV:NavController){
         | ^ 11 | this.nav =资产净值; 12 | 13 | this.items = [


  

正如你所看到的,似乎觉得有什么不对的结肠。但是,如果您删除冒号,那么你得到一个类似的错误,其中的空间吧。

下面是完整的code:

\r
\r

进口{页面,NavController}从'离子角;\r
进口{} AddItemPage从'../add-item/add-item';\r
\r
\r
@页({\r
  templateUrl:构建/页/表/ list.html\r
})\r
\r
出口类末页{\r
  构造函数(NAV:NavController){\r
    this.nav =资产净值;\r
\r
    this.items = [\r
      {'标题':'你好','描述':'你好'},\r
      {'标题':'SADF','描述':'asdfasdf'},\r
      {'标题':'ASD,说明:ASDF}\r
    ];\r
  }\r
\r
  新增项目()\r
  {\r
    this.nav.push(AddItemPage,{末页:此});\r
  }\r
}

\r

\r
\r

任何想法可能会导致这种情况发生?


解决方案

您的错误让我觉得你尝试直接,而不必编译(preprocessing)或transpiled它在飞行以执行打字稿code。

我觉得你的code只应ES6。事实上,随着ES6,你有一流的支持,但不会打字支持(在构造例如/法)。

我看了一下Ionic2生成模板,他们似乎是ES6。请参阅此链接:

您可以调整你的code是这样的:

 进口{页面,NavController}从'离子角;
进口{} AddItemPage从'../add-item/add-item';
@页({
  templateUrl:构建/页/表/ list.html
})出口类末页{
  静态get参数(){
    返回[[NavController]];
  }  构造函数(NAV){
    this.nav =资产净值;    this.items = [
      {'标题':'你好','描述':'你好'},
      {'标题':'SADF','描述':'asdfasdf'},
      {'标题':'ASD,说明:ASDF}
    ];
  }  新增项目()
  {
    this.nav.push(AddItemPage,{末页:此});
  }
}

While following the tutorial here I get to the point where I am getting a syntax error while compiling my typescript code.

Here is the error:

/app/pages/list/list.js Module build failed: SyntaxError: /focus/projects/ionic-todo/app/pages/list/list.js: Unexpected token (10:17) 8 | 9 | export class ListPage {

10 | constructor(nav: NavController){ | ^ 11 | this.nav = nav; 12 | 13 | this.items = [

As you can see, it seems to think there is something wrong with the colon. However if you remove the colon then you get a similar error where the space is instead.

Here is the full code:

import {Page, NavController} from 'ionic-angular';
import {AddItemPage} from '../add-item/add-item';


@Page({
  templateUrl: 'build/pages/list/list.html'
})

export class ListPage {
  constructor(nav: NavController){
    this.nav = nav;

    this.items = [
      {'title': 'hi', 'description': 'hello'},
      {'title': 'sadf', 'description': 'asdfasdf'},
      {'title': 'asd', 'description': 'asdf'}
    ];
  }

  addItem()
  {
    this.nav.push(AddItemPage, {ListPage: this});
  }
}

Any ideas what could be causing this to happen?

解决方案

Your error let me think that you try to execute directly your TypeScript code without having compiled (preprocessing) or transpiled it on the fly.

I think that your code should be ES6 only. In fact, with ES6, you have the class support but not type support (in constructor / method for example).

I had a look at Ionic2 generator templates and they seem to be ES6. See this link:

You could adapt your code like this:

import {Page, NavController} from 'ionic-angular';
import {AddItemPage} from '../add-item/add-item';


@Page({
  templateUrl: 'build/pages/list/list.html'
})

export class ListPage {
  static get parameters() {
    return [[NavController]];
  }

  constructor(nav){
    this.nav = nav;

    this.items = [
      {'title': 'hi', 'description': 'hello'},
      {'title': 'sadf', 'description': 'asdfasdf'},
      {'title': 'asd', 'description': 'asdf'}
    ];
  }

  addItem()
  {
    this.nav.push(AddItemPage, {ListPage: this});
  }
}

这篇关于离子2语法错误在编译时打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆