Components are way of organizing the UI code for structure wise and promote code re-usability for a large application.
ko.components.register('componentname', {
viewModel: {...},
template: {....)
}); <!DOCTYPE html>
<head>
<title>Components of KnockoutJS</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
</head>
<body>
<h4>Example 1: without parameters</h4>
<div data-bind='component: "example-editor"'></div>
<h4>Example 2: passing parameters</h4>
<div data-bind='component: {name: "example-editor", params: { initialText: "Hi! there." }}'></div>
<script>
ko.components.register('example-editor', {
viewModel: function(params) {
this.str = ko.observable(params && params.initialText || '');
},
template: 'Result: <input data-bind="value: str" /> ' + '<br />' + 'Characters: <span data-bind="text: str().length"></span>'
});
ko.applyBindings();
</script>
</body>
</html> People usually stumble onto the 461 visa when they realise there’s no simple way to…
In today’s digital era, people look for convenience, transparency, and genuine rewards from their financial…
If you are planning to start a lighting business and looking for a supplier of…
If you are a copywriter or a content marketer, you will second my statement that…
Motorcycle accidents often lead to severe injuries because riders have minimal protection compared to drivers…
No business owner starts his or her business with the hope of making losses. Everyone…