Skip to content

Cannot read property 'childrenProperty' of undefined #3

Open
@mikeddol

Description

@mikeddol

I have installed your module using bower, did all the correct linking into the project. Then added your module as a dependency in my module and used it in a component.
The component looks something like this:

(function () {
    angular.module('tree-dropdown', [
        'angularjsDropdownTree'
    ]);

    angular.module('tree-dropdown').component('treeDropdown', {
        templateUrl: 'some-place/tree-dropdown/tree-dropdown.tpl.html',
        controller: 'TreeDropdownController',
        bindings: {
            options: '<',
            change: '&'
        }
    });

    angular.module('tree-dropdown').controller('TreeDropdownController', TreeDropdownController);

    TreeDropdownController.$inject = [];
    function TreeDropdownController() {
        var ctrl = this;

        ctrl.settings = {
            selectionLimit: 1,
            childrenProperty: 'theChild',
            disableSearch: true,
            subProperty: 'theChild'
        };

        ctrl.onSelected = function (selection) {

        };
    }
})();

The template looks like this:
<dropdown-tree selection-changed="$ctrl.onSelected(selection)" options="$ctrl.thing" settings="$ctrl.settings"></dropdown-tree>

The data coming through the options binding comes through and looks something like this:

[
    {name: 'a', uuid: 1, theChild: []
    },
    {name:'b', uuid: 2, theChild: [
            {name:'c', uuid: 3, theChild: []
            },
            {name:'d', uuid: 4, theChild: [
                    {name:'e',uuid: 5,theChild: []
                    }
                ]
            }
        ]
    }
]

Now, the options are coming through because I can access them from $onInit in my component, the settings seem to be set because I've enabled and disabled search in the dropdown; but for some reason it doesn't display any data. None of the options.

Moreover I'm getting the following error in the console:

 TypeError: Cannot read property 'childrenProperty' of undefined
    at e.value (component.js:formatted:261)
    at e.value (component.js:formatted:145)
    at new e (component.js:formatted:118)
    at Object.invoke (angular.js:5003)
    at $controllerInit (angular.js:10866)
    at nodeLinkFn (angular.js:9746)
    at angular.js:10154
    at processQueue (angular.js:16832)
    at angular.js:16876
    at Scope.$digest (angular.js:17971)

I have also tried to use it without the settings parameter and it throws the same error.

Any idea what the problem could be? To me it looks like either the this or the this.settings is undefined in that context..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions