Search code examples
angularamcharts

Access to Protected methods in Angular Class


Is there a way to get access to protected properties of an Angular Library Class from an Angular app?

For example, I need to get the value that is in a protected property _gridInterval from the Class "DateAxes" of the library amChart4

But, things like:

dateAxis._gridInterval

Give me the error message:

error TS2445: Property '_gridInterval' is protected and only accessible within class 'DateAxis' and its subclasses.

I know that it is not a Good Practice (try to access to protected values) but I need to get that value.

Thanks


Solution

  • It’s probably not such a good idea, but if you must do it, you could try something like this:

    dateAxis['_gridInterval']
    

    This might also work:

    const da: any = dateAxis;
    da._gridInterval