Ionic error, when trying to compile with ionic serve

0

I get the following error:

  

declared by the module 'AppModule'. Please add to @ Pipe / @ Directive / @ Component annotation

Where app.module.ts :

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';

import { TabsPage } from '../pages/tabs/tabs';

import { PendientesPage } from '../pages/pendientes/pendientes';
import { LeidosPage } from '../pages/leidos/leidos';
import { TodosPage } from '../pages/todos/todos';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
//utilitarios
import { GenerarCodigoControl } from '../utilitarios/generar.codigo.control';

@NgModule({
  declarations: [
    MyApp,
    TodosPage,
    LeidosPage,
    PendientesPage,
    TabsPage,
    GenerarCodigoControl
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    TodosPage,
    LeidosPage,
    PendientesPage,
    TabsPage,
    GenerarCodigoControl
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

And the other GenerarCodigoControl code:

import { Validar } from './validar';
import { AllegedRc4 } from './allegedrc4';
import { Base64 } from './base64';
import { Verhoeff } from './verhoeff';
export class GenerarCodigoControl {
          //var oValidar: Validar;
           constructor(private oValidar:Validar, private oAllegedRc4:AllegedRc4, private oBase64:Base64,private oVerhoeff:Verhoeff){
           }
          enviarDatos1(){
           this.oValidar.validarDatos(2345,334,45,'25/09/2018',232,'Sesamo');
          }
}

What is the error? Thanks in advance.

    
asked by joselo 11.10.2018 в 22:13
source

1 answer

1

The error is shown because the component you are adding does not have the annotation @Component({...})

To solve the error you need to add something like this:

...
@Component({
    selector: 'app-generar-codigo-control',
    templateUrl: './generar-codigo-control.component.html'  
})
export class GenerarCodigoControl {
    //var oValidar: Validar;
    constructor(private oValidar: Validar, private oAllegedRc4: AllegedRc4, private oBase64: Base64, private oVerhoeff: Verhoeff) {}
    enviarDatos1() {
        this.oValidar.validarDatos(2345, 334, 45, '25/09/2018', 232, 'Sesamo');
    }
}
...

Without this information Angular does not know how to process your component.

For more information you can check the official documentation:

link

EDIT:

Whereas you want to add the GenerarCodigoControl class as a service, you need to add the annotation @Injectable in the following way:

...
@Injectable()
export class GenerarCodigoControl {
        ...
    }
}
...

Immediately injecting this service through the constructor of the class where you want to use it, you can use it without any problem.

    
answered by 11.10.2018 в 22:37