Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

452
Views
Texto mecanografiado: el código no se puede compilar a partir del error TS1128: se esperaba una declaración o declaración, pero se ejecuta como se esperaba cuando entrego el código

Estoy desarrollando un proyecto Angular2 y creé una clase que sirve como mi clase de componente principal:

 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; } } }

Cuando ejecuto npm start (que ejecutará tsc -p ./), obtengo los siguientes dos errores:

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

En las siguientes líneas de código

 ---> public submitToJSON() { //SumbitJSON Object var submitJSON = { //inputData }; this.sService.POST(submitJSON); }

Y en la última línea del código. He estado modificando el código todo el día, y solo se soluciona eliminando el código relacionado con OnInit. ¿Qué estoy haciendo mal? Soy nuevo en Angular2, por lo que cualquier información sería útil. También estoy ejecutando tsc versión 3.1

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

En mi caso solo fue necesario volver a compilar el proyecto

over 4 years ago · Santiago Trujillo Report

0

Acabo de tener el mismo error y desapareció después de cerrar IntelliJ y volver a abrir. Yo había estado modificando el archivo con el error. Es como si estuviera mirando una versión antigua de alguna manera.

over 4 years ago · Santiago Trujillo Report

0

has comentado

 //inputData };

Creo que la llave debería estar en la siguiente línea...

 //inputData };

Editar

Su función ngOnInit no debe contener otras funciones:

 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; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!