angular - Typescript - Code fails to build from error TS1128: Declaration or Statement expected, but runs as expected when I serve the code -


i developing angular2 project, , created class serves main component class:

import { component, oninit} '@angular/core';  import { submitservice } './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 >= && index <= to) {                     entries.push( obj[key]);                 }             }             return entries;             }   }  } 

when run npm start (which run tsc -p ./), following 2 errors:

app.appcomponent.ts: error ts1128:declaration or statement expected app.appcomponent.ts: error ts1128:declaration or statement expected 

at following lines of code

---> public submittojson() {       //sumbitjson object         var submitjson = {             //inputdata };          this.sservice.post(submitjson);  } 

and @ last line of code. have been modifying code whole day, , removing oninit related code fixes it. doing wrong? i'm new angular2, information helpful. running tsc version 3.1

you have commented

//inputdata }; 

i think curly brace should on next line...

//inputdata }; 

edit

your ngoninit function should not contain other functions:

import { component, oninit} '@angular/core';  import { submitservice } './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 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 >= && index <= to) {                 entries.push( obj[key]);             }         }         return entries;         }    } 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -