Questions tagged inheritance

Explore the latest questions and answers asked by our top developers.

Angular service injecting another service (both children of same abstract class) can’t access injected service’s methods ("reading undefined")

I have multiple services handling notably API requests for different resources. As they’re very similar, I created a parent abstract generic class like this: abstract class GenericService<T>{ foo(){ bar(); } abstract bar(); } But they’re also highly interconnected so I have a lot of them injected into others: class R1Service extends GenericService<R1>{ … bar(){/*do something*/}; […]

C# IFormFile wrapper class

I feel like this is a pretty easy thing to do but for some reason in my code I keep getting an HTTP 415 error message. The front end is Angular and the backend is C# .NET. I am making a post to upload formData. My problem is happening when I the form is submitted […]

By kpgabriel
Categorized as angular, c#, deserialization, inheritance Tagged , , ,

Angular Library base class without any decorator but using Angular features

I came across this in the Angular migration guide. I’m a library author. Should I add the @Directive() decorator to base classes? As support for selectorless decorators is introduced in Angular version 9, if you want to support Angular version 8 and earlier, you shouldn’t add a selectorless @Directive() decorator. You can either add […]

How to use inherited service declared in the constructor in angular

I try to create a baseComponent, which will be then extended by many other components. I’m trying to pass a service through super() but I get a Cannot read properties of undefined What I tried @Directive() export class BaseComponent { constructor(public componentService: baseService) { console.log( // Cannot read properties of undefined "foo" } } @Directive() […]

By Rapha l Balet
Categorized as angular, constructor, inheritance Tagged , ,

Angular 12.2.9. and TypeScript – Is it possible for a service implementation to extend the abstract service it implements rather than implement it?

I have a situation where I have methods that return data they receive from a web service call; the thing is, depending on certain things, the web service will return data that already conforms to the interfaces these methods need to return, but in other cases the same methods will have to process the data, […]

How to reuse injection token without injecting again in angular child service classes?

I have a parent service called BaseStoreService and it looks like this: import { ENV_TOKEN } from ‘../constants/global.constants’ export class BaseStoreService<T> extends ObservableStore<T> { constructor(@Inject(ENV_TOKEN) env: {production: boolean}) { super({ trackStateHistory: false, logStateChanges: !env.production}); } } I have another child service called QuoteStoreService and it looks like this: export class QuoteProcessingStoreService extends BaseStoreService<QuoteProcessingStore> { constructor(env […]

By KZoeps
Categorized as angular, angular-services, inheritance Tagged , ,

Dependency inheritance in Angular components – using subclass of dependency?

I’ve created a "CrudComponent" that basically performs CRUD operations, with a dynamically generated datatable view and input form and whatnot. The component injects a "DataService" with functions which basically wrap fetch functions, which are called on the component’s instance of DataService to send and retrieve data from the server. export class CrudComponent{ constructor(private dataService:DataService){ … […]

How to declare an abstract class with @Directive decorator in the module

I have an abstract BaseChartComponent that other components (e.g. LineChartComponent) inherit from. Because it has @Inputs, it needs an @Directive decoorator to function. @Directive() export abstract class BaseChartComponent implements AfterViewInit, OnDestroy { @Input() public set someInput(value: string) … / } Setting the @Directive() yields the error BaseChartComponent is not declared in any Angular module. However, […]

By Teresa
Categorized as angular, inheritance Tagged ,

Best practice in Angular: Use inheritance, services or other for these similar components?

I am using the dataviz library amcharts to display various types of graphs in my application. While all slightly different, they are very much alike in other regards. Look at an example: export class GanttChartComponent { public constructor(…) { … } private initializeChart(): void { useTheme(amchartsdark); options.autoSetClassName = true; this._chart = this.createChart(); this.configureChart(); this.configureXAxis(); this.configureYAxis(); […]

By Teresa
Categorized as amcharts, angular, inheritance, typescript Tagged , , ,

Reference for typescript parent or its child class in Angular HTML template

I have a problem with typescript inheritance and property reference in Angular HTML template and couldn’t solve it for a long time. (if it’s question duplication, sorry for that, I couldn’t find question like this). So I have a parent interface, let it call DummyParent with some properties. export interface DummyParent { dummy1?: string; dummy2?: […]

By faklyasgy
Categorized as angular, html, inheritance, typescript Tagged , , ,
1 2 3 4

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us