Skip to content

(AOT): Angular does not invoke lifecycle listeners if typescript mixins are used #19145

Description

@kemsky

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Assume we have base class, mixin and component class:

class Base implements OnInit {
    constructor(){}
    ngOnInit():void {}
}

type Constructor<T> = new(...args: any[]) => T;

function Tagged<T extends Constructor<{}>>(base: T) {
    return class extends base {
        value: string;
        constructor(...args: any[]) {
            super(...args);
            this.value= "test";
        }
    }
}

export class Component extends Tagged(Base) {
    public item:any;

    constructor()  {
        super();
    }
}

Component's ngOnInit listener will not be called in AOT.

Workaround:

export class Component extends Tagged(Base) {
    public item:any;

    constructor() {
        super();
    }

   ngOnInit():void {
         super.ngOnInit();
   }
}

Expected behavior

ngOnInit should be called.

Environment


Angular version: 4.4.0-RC.0
TypeScript: 2.4.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecore: lifecycle hooksfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions