knockout component with custom element styling
HTML
<script src="http://knockoutjs.com/downloads/knockout-3.2.0.js"></script>
<h4>First instance, without parameters</h4>
<message-editor></message-editor>
<h4>Second instance, passing parameters</h4>
<message-editor params="initialText: 'Hello, world!'"></message-editor>
CSS
message-editor {
font-size: 19px;
}
JavaScript
ko.components.register('message-editor', {
viewModel: function(params) {
this.text = ko.observable(params && params.initialText || '');
},
template: 'Message: <input data-bind="textInput: text" /> '
+ '(length: <span data-bind="text: text().length"></span>)'
});
ko.applyBindings();