knockout.js - Bundle Knockout components with r.js -
i include knockout custom components bundled js (with r.js) not need loaded via amd.
using syntax, component's code included in bundle:
requirejs(['knockout'],function(ko) { ko.components.register('like-widget', { viewmodel: function(params) { // data: value either null, 'like', or 'dislike' this.chosenvalue = params.value; // behaviors this.like = function() { this.chosenvalue('like'); }.bind(this); this.dislike = function() { this.chosenvalue('dislike'); }.bind(this); }, template: '<div class="like-or-dislike" data-bind="visible: !chosenvalue()">\ <button data-bind="click: like">like it</button>\ <button data-bind="click: dislike">dislike it</button>\ </div>\ <div class="result" data-bind="visible: chosenvalue">\ <strong data-bind="text: chosenvalue"></strong> it\ </div>' }); }); i want keep viewmodel , template separate files use syntax:
requirejs(['knockout'], function(ko) { ko.components.register('like-button', {require: 'components/like-button'}); }); however using syntax, component's files not included in bundle , requested when component should render.
is there way component's viewmodel , template included in bundle?
Comments
Post a Comment