angular - Typescript - 代码无法从错误 TS1128 : Declaration or Statement expected, 生成,但在我提供代码时按预期运行

标签 angular npm

我正在开发一个 Angular2 项目,我创建了一个类作为我的主要组件类:

import { Component, OnInit} from '@angular/core';

import { submitService } from './Common-functions/submit.service';

@Component({
selector: 'my-app',
template: `htmlCode`

})
export class AppComponent implements OnInit{ 
  hideTable = true;
  lengthOfRecords = 0;
  lowerLimit = 0;
  upperLimit = 5;
  prevButtonDisabled = true;
  nextButtonDisabled = false;

  //User inputs

constructor(private sService:submitService) { }

ngOnInit() {
    public submitToJSON() {

         //SumbitJSON Object
            var submitJSON = {
                //inputData 
                     };

            this.sService.POST(submitJSON);
     }


   public returnDetails() {

    this.listOfIDs = {//ListData};

            this.hideTable = false;
        var keys = Object.keys(this.listOfIDs);
            var len = keys.length;
            this.lengthOfRecords = len;
        }

    public prev() {
            if(this.lowerLimit <= 0) {
                ;
                }
            else {
                this.lowerLimit = this.lowerLimit - 6;
                this.upperLimit = this.upperLimit - 5;
                this.nextButtonDisabled = false;
                if(this.lowerLimit <= 0) {
                    this.prevButtonDisabled = true;
                    }
                }
            }
   public next() {
            if(this.upperLimit >= this.lengthOfRecords) {
                ;
                }
            else {
                this.lowerLimit = this.lowerLimit + 6;
                this.upperLimit = this.upperLimit + 5;
                this.prevButtonDisabled = false;
                if(this.upperLimit >= this.lengthOfRecords) {
                    this.nextButtonDisabled = true;
                    }
                }
            }

 getEntries(obj, from, to) {
        if(obj!=null) {
            var entries = [];
            for(var key in obj) {
                // extract index after `app`
                var index = key.substring(3);
                if(index >= from && index <= to) {
                    entries.push( obj[key]);
                }
            }
            return entries;
            }

 }

}

当我运行 npm start(将运行 tsc -p ./)时,出现以下两个错误:

app.appComponent.ts: error TS1128:Declaration or statement expected
app.appComponent.ts: error TS1128:Declaration or statement expected

在下面的代码行

---> public submitToJSON() {

     //SumbitJSON Object
        var submitJSON = {
            //inputData };

        this.sService.POST(submitJSON);
 }

在代码的最后一行。一整天都在修改代码,只去掉了OnInit相关的代码就解决了。我究竟做错了什么?我是 Angular2 的新手,所以任何信息都会有所帮助。我也在运行 tsc 3.1 版

最佳答案

在我的例子中,只需要重新编译项目

关于angular - Typescript - 代码无法从错误 TS1128 : Declaration or Statement expected, 生成,但在我提供代码时按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43284162/

相关文章:

javascript - 如何在数组 typescript 中设置对象

angular - 检查用户是否已滚动到 Angular 2 的底部

node.js - Node : Get dependencies licence

node.js - 如何覆盖 Windows 树命令?

Angular Testing 抛出错误

javascript - ngx 完美滚动条更新功能未定义?

c# - Angular - 如何在 subscribe() 上从 Web API 下载文件

javascript - npm 与 webpack 的链接 - 找不到模块

javascript - Webpack:将当前条目名称传递给 js?

node.js - JointJS 依赖管理问题