Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

Angular 6 and typescript child class extends from parent class and banish child variables

$
0
0

I have an abstract class called ParentService and its child classChildService as follows:

ParentService

import { Injectable } from '@angular/core';
import { MyModel} from './mymodel-model.service';
@Injectable({
  providedIn: 'root'
})
export abstract class ParentService {
  constructor() { }
  word:MyModel = { 
    "AA":"AA",
    "BB":"BB",
  }
}

ChildService

import { Injectable } from '@angular/core';
import { MyModel} from './mymodel-model.service';
import { ParentService } from './parent.service';
@Injectable({
  providedIn: 'root'
})
export class ChildService extends ParentService {
  word2:MyModel = {
    "AA":"AA2",
    "BB":"BB2",
  };
}

In the constructor of the app-component I have declared the child instance as follows:

constructor(private child_instance:ChildService){}

When printing child_instance in the browser console I get:

 ParentService {word: {…}}

Without the extends ParentService I got:

 ChildService {word2: {…}}

But I need to have both variables in the same class:

ChildService {word: {…},word2: {…}}
//or
ParentService {word: {…},word2: {…}}

How can I acomplish this?


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>