Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:52:58+00:00 2026-06-15T17:52:58+00:00

I have recently started to work with requirejs and when I try to create

  • 0

I have recently started to work with requirejs and when I try to create a simple viewmodel I get an strange exception. The exception comes from the knockout-2.1.0.js file and the exception is “Only subscribable things can act as dependencies”.

define("PageViewModel", ["knockout-2.1.0"], function(ko) {
    return function PageViewModel() {
        var self = this;
        self.visiblePage = ko.observable("StartPage");
        self.showPage = function (pageName) {
            self.visiblePage(pageName);
        };
    };
});

As you can see the viewmodel is extremly simple and since the error is in the knockout js file, it seems like requirejs is working as it should. I have been looking at: http://knockoutjs.com/documentation/amd-loading.html
The exception occur when coming to the line: self.visiblePage = ko.observable(“StartPage”);

Any ideas on what I’m doing wrong?

Thanks,
Ludwig

Update:
This is the module containing the pageviewmodel:

define("ViewModelFactory", ["StorageService", "PageViewModel", "AddUnitViewModel", "AddRoomViewModel"],
function (StorageService, PageViewModel, AddUnitViewModel, AddRoomViewModel) {
    //var repositoryStorage = new StorageService();
    var createAddRoomVM = function () {
        var vm = new AddRoomViewModel();
        vm.setRepository = StorageService.getRoomRepository();
        return vm;
    };
    var createAddUnitVM = function () {
        var vm = new AddUnitViewModel();
        vm.setRepository = StorageService.getUnitRepository();
        return vm;
    };
    var createPageVM = function () {
        var vm = new PageViewModel();
        return vm;
    };

    return {
        createPageVM:createPageVM,
        createAddRoomVM: createAddRoomVM,
        createAddUnitVM: createAddUnitVM
    };
});

And the module calling the factory

define("ApplicationViewModel", ["ViewModelFactory"],
function (viewModelFactory) {
    mainVM = null;
    var initVM = function () {
        mainVM = {
            page: viewModelFactory.createPageVM(),
            addRoom: viewModelFactory.createAddRoomVM(),
            addUnit: viewModelFactory.createAddUnitVM()
        };
    };

    var getVM = function (viewName) {
        switch (viewName) {
            case "AddRoom":
                return mainVM.addRoom;
            case "AddUnit":
                return mainVM.addUnit;
            default:
                return null;
        }
    };
    var getPageVM = function () {
        return mainVM.page;
    };

    return {
        initVM: initVM,
        getVM: getVM,
        getPageVM: getPageVM,
        mainVM: mainVM
    };
});

And the class containing the applicationViewModel:

define("Bootstrapper", ["knockout-2.1.0", "Routing", "ApplicationViewModel"],
function (ko, routing, applicationViewModel) {
    var run = function () {
        applicationViewModel.initVM(); <-- after here mainVM.page is null
        var mainVM = applicationViewModel.mainVM;
        routing.initRouting(applicationViewModel);
        ko.applyBindings(mainVM);
        routing.showView("StartPage");
        alert("Start");
    };

    return {
        run: run
    };
})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:53:00+00:00Added an answer on June 15, 2026 at 5:53 pm

    Your problem may have been caused by Knockout 2.1, which didn’t work well when ko was not a global variable.

    Knockout 2.2 should work fine, and I see from your comment this did indeed fix the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An application I have recently started work on has to register two dll's, because
I have started to work on maven project recently. The piece of code I
I have recently started work on an application that is already deployed to production.
I have recently started work on a large project in .net (C#) and I
I have recently started using automapper and it has work fine for me so
I have recently started applying for .Net jobs. I currently work in a sales
I have recently started following the examples from The Little Schemer and when trying
I have recently started work on an existing WordPress site. The theme on the
I have recently started learning Silverlight and can't figure out how make this work.
I have recently started to work with RavenDB. Here's a traditional example in relational

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.