Home > Mobile >  Typescript inherit a variable from superclass
Typescript inherit a variable from superclass

Time:01-10

Let's say I have 2 components:

export class BaseComponent {
    succesfullSave: boolean;
}


export class InheritComponent extends BaseComponent {
    isButtonDisabled() {
        return !super.succesfullSave;
    }
}

in my InheritComponent html, I have a button with a disabled directive:

<button [disabled]="isButtonDisabled()"></button>

After changing the succesfullSave property value, the button is still enabled.

Angular doesn't look for value change when inheriting a value from superclass?

CodePudding user response:

disable attribute accepts a value not a functional. So i think creating a get property would a solve the issue.

get isButtonDisabled():boolean=>!super.succesfullSave;

CodePudding user response:

Should be just this.succesfullSave.

You need super. to access a method of your base class, but you have overridden it in your child (extending) class.

  •  Tags:  
  • Related