0
votes

I am using the Hot Towel template by John Papa. I have a html view called nav.html, which contains the header portion of my spa. Within that, i need to display the name of the person that is logged into the system (i have a server side utility class that handles the query).
The following is from the html in the nav.html view for that- data-bind="text: LoggedInAs"

Here is the viewmodel code (nav.js)-

define(['services/logger'], function (logger) {
    var vm = {
        activate: activate,
        title: 'Nav View'
    };

    return vm;

    //#region Internal Methods
    function activate() {
        logger.log('Nav View Activated', null, 'Nav', true);
        return true;
    }
    //#endregion
});

My problem is that i am not sure how to do this. i tried adding nav.js to my viewmodels folder, but the javascript does not run. I thought durandal would have picked it up like the other viewmodels. The only difference between the nav.js and the other view models is that the other view models are triggered by clicking on a link (wired through route.mapnav).

What am i missing here? How do i get the javascript to run without a user clicking on a link? When the page loads, I need nav.js to run in order to populate the LoggedInAs data-bind.

1
Did you include the nav-view in your shell? It will not be loaded if it's not part of the page. - Kenneth
Ken- I did- <header> <!--ko compose: {view: 'nav'} --><!--/ko--> </header> - Chris

1 Answers

0
votes

Make sure that you are activating your nav view. In the example code you have given in the comment above, it would need to be this:

<header> <!--ko compose: {view: 'nav', activate: true} --><!--/ko--> </header>