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> Online trading has brought ease of trading, better security protocols, and fast trade executions; however,…
Very few brands suffer from a product issue. It's a conversion issue. People enter DMart,…
The onboarding process of the retailer, distributor, or partner may soon become problematic if there…
Many of the states in the United States of America allow the use of medical…
Did you know that every time you browse this website or any other, you leave…
Online casino has gained immense popularity with the rise of online casinos. Platforms like GameZone…