0

Hi I have a situation where I need to compose only a view and not a viewModel for this I have set this composition statement in my html:

<!-- ko compose: { view : content }-->
<!--/ko-->

Content represent an observable from my viewmodel.

The problem is that it seems the framework is also trying to download the viewmodel which does not exist and has no reason to exist.

Does anyon no how to stop Durandal from looking for the viewModel?

I have tryed setting the model : null but it did not work

aleczandru
  • 5,319
  • 15
  • 62
  • 112

3 Answers3

1

You can't stop Durandal looking for the view model if you're using the compose binding, but there are a number of things you can do to prevent loading a new model:

  • Point Durandal to a dummy object to use as the model (e.g. create a singleton dummyModel.js);

  • Use a "dumb" object (for example an array) for your model:

    <!-- ko compose: { view : content, model: [] }--><!--/ko-->

  • Use the current model, and turn off activation (to prevent activate being called on the model twice):

    <!-- ko compose: { view : content, model: $data, activate: false }--><!--/ko-->

Basically, Durandal doesn't care what you give it as a model, as long as it has something to use. Note that it will still bind whatever model you specify to your view though!

gerrod
  • 6,119
  • 6
  • 33
  • 45
0

try this

<div>
   <div data-bind="compose:'views/content.html'"></div>
</div>
Akhlesh
  • 2,389
  • 1
  • 16
  • 23
  • it seems to have the same effect the only difference from what you posted is that if I add views/content.html durandal will look at views/views/content.html – aleczandru Feb 23 '14 at 14:04
0

I am not sure if this will answer your question but I did come across a similar situation where I wanted to load views of my application which had no viewmodels. I created a module which given the view would load the view for me. All I had to was overwrite the getView function of my custom viewmodel which loaded my views.

//viewLoader --> it's job is to load the views which do not have any viewmodels
define(['plugins/router], function(router){
   return {
      getView: function() {
      return "views/"+router.activeInstruction().config.file +".html";
     }
   }
}
nimgrg
  • 582
  • 1
  • 7
  • 17