0

Anyone understand why I am getting an undefined error?

export abstract class BaseEditorComponent implements IPropertyEditor, OnDestroy {

  @Input()
  public element: BpmnJS.IRegistryElement; 

--more code here


export class CommonPropertiesEditorComponent extends BaseEditorComponent {

  constructor(
  ) {
    super();
  }

  public get elementId(): string {
    return this.element.id;
  } 

export class ExclusiveGatewayEditorComponent extends CommonPropertiesEditorComponent implements OnInit {

  public model: IUserTaskDef;
  public outGoing: Sequences[];

  constructor(
    private service: ExclusiveGatewayService
  ) {
    super();
    this.model = {} as any;
    this.outGoing = this.getOutGoingSequences();
  }

  public getOutGoingSequences(): Sequences[] {

    return this.service.getOutgoingSequences(this.elementId); //This is undefined.
  }

TypeError: Cannot read property 'id' of undefined at ExclusiveGatewayEditorComponent.get [as elementId] (common-properties-editor.component.ts:16) at ExclusiveGatewayEditorComponent.push../src/app/properties/editors/gateways/exclusive-gateway/exclusive-gateway-editor.component.ts.ExclusiveGatewayEditorComponent.getOutGoingSequences (exclusive-gateway-editor.component.ts:27) at new ExclusiveGatewayEditorComponent (exclusive-gateway-editor.component.ts:22) at createClass (core.js:21148) at createDirectiveInstance (core.js:21027) at createViewNodes (core.js:29387) at createRootView (core.js:29301) at callWithDebugContext (core.js:30309) at Object.debugCreateRootView [as createRootView] (core.js:29819) at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:20506)

If I enter the same function into the html page it works fine and displays the value of element.id

<input class="form-control" type="text" name="txtId" [(ngModel)]="elementId" readonly>

1 Answer 1

1

You should not try to access @Input() properties from constructor, they do not exist at this point. You should do it in ngOnInit() method instead.

export class ExclusiveGatewayEditorComponent extends CommonPropertiesEditorComponent implements OnInit {

  // ...

  constructor(
    private service: ExclusiveGatewayService
  ) {
    super();
    this.model = {} as any;    
  }

  ngOnInit() {
    this.outGoing = this.getOutGoingSequences();
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.