我正在开发Angular2项目,并创建了一个用作我的主要Component类的类:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行npm start(将运行tsc -p ./)时,出现以下两个错误:
app.appComponent.ts: error TS1128:Declaration or statement expected
app.appComponent.ts: error TS1128:Declaration or statement expected
Run Code Online (Sandbox Code Playgroud)
在以下代码行
---> public submitToJSON() {
//SumbitJSON Object
var submitJSON = {
//inputData };
this.sService.POST(submitJSON);
}
Run Code Online (Sandbox Code Playgroud)
并在代码的最后一行。我整天都在修改代码,只有删除与OnInit相关的代码才能解决该问题。我究竟做错了什么?我是Angular2的新手,所以任何信息都将对您有所帮助。我也在运行tsc 3.1版
Jöc*_*ker 28
在我的情况下只需要再次编译项目
Mar*_*son 14
只是遇到了同样的错误,在关闭 IntelliJ 并重新打开后它就消失了。我一直在修改带有错误的文件。就好像它在以某种方式查看旧版本。
你评论了
//inputData };
Run Code Online (Sandbox Code Playgroud)
我认为大括号应该在下一行...
//inputData
};
Run Code Online (Sandbox Code Playgroud)
编辑
您的ngOnInit函数不应包含其他函数:
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() {
// Add any initialization code here
}
submitToJSON() {
//SumbitJSON Object
var submitJSON = {
//inputData
};
this.sService.POST(submitJSON);
}
returnDetails() {
this.listOfIDs = {//ListData};
this.hideTable = false;
var keys = Object.keys(this.listOfIDs);
var len = keys.length;
this.lengthOfRecords = len;
}
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;
}
}
}
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18279 次 |
| 最近记录: |