Consider the example base class below:
import { FormBuilder, FormGroup } from '@angular/forms';
import { NavParams, LoadingController, Loading, Events } from 'ionic-angular';
import { IBaseService } from '../../data/interface/ibase-service';
import { MessageUtil } from '../../message/message-util';
export class FormPage<T> {
public form: FormGroup;
public current: T;
public submitAttempt: boolean;
public loading: boolean;
public mode: string;
public id: number;
public loader: Loading;
constructor(public service: IBaseService<T>,
public fb: FormBuilder,
public events: Events,
public messageUtil: MessageUtil,
public navParams: NavParams,
public loadingCtrl: LoadingController) {
let me = this;
me.mode = navParams.get('mode');
me.id = navParams.get('id');
}
}
Now, what I'm trying to do is for the implementing class to only provide/inject the 'service' param w/o the need to pass all other base parameters. Below is the implementing class:
import { Component } from '@angular/core';
import { NavParams, IonicPage, LoadingController, Events } from 'ionic-angular';
import { FormBuilder, FormGroup } from '@angular/forms';
import { MessageUtil } from '../../framework/message/message-util';
import { FormPage } from '../../framework/base/page/form-page';
import { UserService } from '../../providers/user-service';
import { User } from '../../models/user';
@IonicPage()
@Component({
selector: 'page-edit-user',
templateUrl: 'edit-User.html',
providers: [
UserService,
MessageUtil
]
})
export class EditUserPage extends FormPage<User> {
//This is the reality
constructor(public service: UserService,
public fb: FormBuilder,
public events: Events,
public messageUtil: MessageUtil,
public navParams: NavParams,
public loadingCtrl: LoadingController) {
super(service, fb, events, messageUtil, navParams, loadingCtrl);
}
//This is my goal
constructor(public service: UserService) {
super(service);
}
}
The goal if possible is to not pass all angular and ionic components since they're provided/declared already at the Base class level and that the implementing class should only deal w/ the service to avoid boilerplate code.