Knockout component registration and module loading (requirejs)

61 views
Skip to first unread message

Nikita Traubenberg

unread,
Jul 26, 2016, 4:11:01 PM7/26/16
to KnockoutJS
I'm trying to use Knockout component registration with requirejs module loader and it is not loading component files. No errors, no requests for the files. Does not seem to call the require function at all.

        $(document).ready(function () {

            require(['knockout-3.3.0'], function (ko) {
                ko.components.register('rio-top-nav', {
                    viewModel: { require: 'Scripts/TopNavViewModel' },
                    template: { require: 'text!Content/TopNavView.html' }
                });
            });
        });

here is my viewModel (declared in the file TopNavViewModel.js):

define(['knockout-3.3.0'],
    function (ko) {
        function TopNavigationViewModel() {
            ...
        };

        $.getJSON("/MyWebAPI/api/topnavigation", function (resp) {

            var mv_TopNav = new TopNavigationViewModel();

            ....

            ko.applyBindings(mv_TopNav);
        });

        return mv_TopNav ;
    });

require.js is loaded, knockout-3.3.0.js is loaded. No idea whats happening, please help!

Thank you

Nikita Traubenberg

unread,
Jul 26, 2016, 4:12:17 PM7/26/16
to KnockoutJS
I mean the first call to require goes through, its the ko.components.register that does not seem to make the call to require().
Reply all
Reply to author
Forward
0 new messages