user1354934
user1354934

Reputation: 8841

In TypeScript, how can I fix an error "property ____ is protected and only accessible within class ____"?

I am working on an angular 2 project and I am using a library called ng2-bootstrap.

I am using modals from this library, and there is a property called _isShown that I am checking in a function inside my class:

  proceed() {
    if (this.childModal._isShown) this.hideChildModal();  // error message here: "[ts] Property '_isShown' is protected and only accessible within class 'ModalDirective' and its subclasses."
    this.router.navigate(['signup-step-two']);
  }

It seems to work even though I get that error, but how can I fix that error correctly?

Thanks

Upvotes: 0

Views: 883

Answers (1)

Sefa
Sefa

Reputation: 8992

Because _isShown is protected in ModalDirective source code. Check it out here.

You can access the public value using isShown() function.

It is declared as public in the source code.

  public get isShown(): boolean {
    return this._isShown;
  }

Upvotes: 2

Related Questions