In angular2, suppose I have a Parent
class and a Child1
class, they have the same properties/members and methods. How to initialize the Child1
class?
Service
@Injectable()
export class Parent {
constructor(
private currentImg: string,
private catImg: string,
private dogImg: string,
private enable: boolean) {
}
onMouseOver() {
enable = true;
currentImg = catImg;
}
onMouseClick() {
enable = false;
currentImg = dogImg;
}
}
One of the child class want to extends Parent
class:
import {Parent} from "./Parent";
@Component({
selector: 'app',
templateUrl: 'app/child.html',
providers: [Parent]
})
export class Child1 {
private currentImg: string = "img/dog.png",
private catImg: string = "img/cat.png",
private dogImg: string = "img/dog.png",
private enable: false
constructor(private _parent: Parent) {
}
onMouseOver() {
this._parent.onMouseOver();
}
onMouseClick() {
this._parent.onMouseClick();
}
}