Since base class doesn't need to be instantiated on its own, it's abstract class and doesn't need to have
@Component
decorator.
If it has dependencies, and there's a chance that
constructor
will be omitted in child classes and inherited, base class should have @Injectable
decorator:@Injectable()
export abstract class BaseComponent implements OnInit {
constructor(public dep: Dep) {}
ngOnInit() {}
}
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent extends BaseComponent {
// dummy constructor can be omitted
/*
constructor(dep: Dep) {
super(dep);
}
*/
}
Không có nhận xét nào:
Đăng nhận xét