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 ?
– NoobSaibot
Expects 2-3 arguments, but has 0. when I put this.task = new Task();
– Diêgo Correia de Andrade
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)
– NoobSaibot
The application now runs, but a new error has arisen.
– Diêgo Correia de Andrade