Expects 2-3 arguments, but has 0. Ionic 2

Asked

Viewed 29 times

0

Guys I’m developing my first application in Ionic 2, and I came across this mistake.

I like to organize my program, so I created some templates... I’m trying to create my page to add/edit a task in a list.

Model:

`import {EstadoTarefa} from "./estado-tarefa";
import { Observable } from "@firebase/util";
export class Tarefa{
  codigo: number;
  titulo: string;
  descricao?:string;
  state:EstadoTarefa


  constructor(codigo: number, titulo: string, descricao?: string){

    this.codigo = codigo
    this.titulo = titulo
    this.descricao = descricao
    this.state = EstadoTarefa.NOVA

  }
}
`

Page to add/edit:

    import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Tarefa } from '../../models/tarefa';
import { LovProvider } from '../../providers/lov/lov';
import { Observable } from '@firebase/util';

@IonicPage()
@Component({
  selector: 'page-cervas-add',
  templateUrl: 'cervas-add.html',
})
export class CervasAddPage {

  tarefa:Tarefa;

  constructor(public navCtrl: NavController, public navParams: NavParams, public lovProvider: LovProvider){

  }

  ionViewDidLoad() {
    this.tarefa = this.navParams.get('tarefa');
    if(!this.tarefa){
     this.tarefa = new Tarefa();
    }
  }



}
  • What mistake did you come across ?

  • Expects 2-3 arguments, but has 0. when I put this.task = new Task();

  • Well, in your constructor you are setting only an optional parameter, that description: descricao?: string if you want to leave the other parameters as optional too, you should do: (codigo?: number, titulo?: string, descricao?: string)

  • The application now runs, but a new error has arisen.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.