Should MVVM ViewModel inject an HTML template for default view?

Posted by explunit on Programmers See other posts from Programmers or by explunit
Published on 2013-03-18T20:20:17Z Indexed on 2013/06/28 4:28 UTC
Read the original article Hit count: 515

Filed under:
|
|

I'm working on web application design that includes Knockout.js and have an overall MVVM question: Does it make sense for the ViewModel to automatically inject a default HTML template (pulled from separate file)?

More detail: suppose I have a site like this...

header...
    widget 1
    widget 2
    widget 3
footer

...and widgets 1/2/3 are going to be Knockout.js ViewModels determined at runtime from an overall list of available widgets, each with associated HTML template file. I understand that in MVVM you want the view (HTML template in this case) to be separate from the ViewModel (Javascript file in this case) so that people can edit it separately and possibly provide multiple templates for different "skins". However, it seems like it would also make sense for the ViewModel to point to a default html template that gets automatically used unless the controlling code provides a different one.

Am I looking at this correctly?

As an example, see this answer on StackOverflow where he recommends injecting the HTML and then the ViewModel. Seems like a one-liner would make more sense in that case, with the possibility of overriding a default template value.

© Programmers or respective owner

Related posts about JavaScript

Related posts about html