考虑下面的示例基类:
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');
}
}
现在,我试图做的是让实现类只提供/注入"服务"参数,而不需要传递所有其他基本参数。 下面是实现类:
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);
}
}
如果可能的话,目标是不传递所有的角度和离子组件,因为它们已经在基类级别提供/声明,并且实现类应该只处理服务以避免样板代码。
如果可能的话,目标是不通过所有的角度和离子成分 因为它们已经在基类级别提供/声明
不,不提供它们。通过调用super(...)
提供所需组件是您,因此您无法避免它