Custom Binders - constructor vs init

2 posts, 0 answers
  1. Justin
    Justin avatar
    4 posts
    Member since:
    Feb 2016

    Posted 29 Jan 2017 Link to this post

    I've been working with adding some custom binders, via typescript, to our project. All of the examples show that overriding the 'init' function is how I am supposed to parse attributes from the elements into (e.g.) custom properties. The issue I'm having is that the overridden 'init' function *never* seems to be called. If I switch to overriding the constructor, instead of init, this works as expected.

    My question is - am I doing this incorrectly, is there anything inherently wrong with overriding the constructor itself, and *why* doesn't the override on init actually fire? I've tried this several ways, at this point I'm exactly duplicating the structure from kendo.d.ts, going with the assumption that the override might not fire if typescript doesn't see an exact match.

    Again, note that the below extension is working - BUT if I were to remove the constructor override, the init override would never be called (confirmed via multiple debugging attempts).

    module {
        export class date extends {
            dateformat: string = "d";
            constructor(element: any, bindings: Bindings, options?: BinderOptions) {
                //call the base constructor
                super(element, bindings, options);
                this.dateformat = $(element).data("dateformat");
            //Note: this NEVER seems to be called
            init(element: any, bindings: Bindings, options?: BinderOptions): void {
                //call the base constructor
      , element, bindings, options);
                this.dateformat = $(element).data("dateformat");
            refresh() {
                var data = this.bindings["date"].get();
                if (data) {
                    var dateObj = new Date(data);
                    $(this.element).text(kendo.toString(dateObj, this.dateformat));
  2. Dimiter Topalov
    Dimiter Topalov avatar
    1296 posts

    Posted 01 Feb 2017 Link to this post

    Hello Justin,

    In general the init() method will not be called automatically in this scenario. You can call it from the constructor. The call to the parent can be performed via super.init() in the init() method if needed, e.g.:

    constructor() {
    init() {

    Calling super() and super.init() from the constructor is also an option, depending on the scenario:

    I hope this helps, but if I am missing something, or you have further questions or issues, related to the topic, do not hesitate to contact us again.

    Dimiter Topalov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top