Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ES6 controller class with angular 1.5.5 has $onInit called before constructor #14469

@ghost

Description

Bug

I'm using ES6 with angular 1.5.5 and using babel to convert to ES5.

export class ReportConfigColumnDialogController {
    constructor($mdDialog, column) {
        'ngInject';

        // fired after $onInit
        this.column = column;

        console.log(this.column.Alias);  // has expected value
    }

    $onInit() {
        // fired first
        console.log(this.column.Alias); // this.column undefined at this point
    }
}

According to the docs at https://code.angularjs.org/1.5.5/docs/guide/component:
$onInit() - Called on each controller after all the controllers on an element have been constructed

That's not what I'm seeing in my code. $onInit got called before the constructor.

BTW, the ES5 code generated by babel looks like this:

var ReportConfigColumnDialogController = exports.ReportConfigColumnDialogController = function () {
        ReportConfigColumnDialogController.$inject = ["$mdDialog", "column"];
        function ReportConfigColumnDialogController($mdDialog, column) {
            'ngInject';

            _classCallCheck(this, ReportConfigColumnDialogController);

            this.column = column;

            console.log(column);

            this.$mdDialog = $mdDialog;
        }

        _createClass(ReportConfigColumnDialogController, [{
            key: '$onInit',
            value: function $onInit() {
                this.aliasQuestion.Answer = this.column.Alias;
            }
        }, {
            key: 'save',
            value: function save() {}
        }, {
            key: 'close',
            value: function close() {
                this.$mdDialog.cancel();
            }
        }]);

        return ReportConfigColumnDialogController;
    }();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions