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> Pain in muscles and joints can be a problem in everyday life, whether it involves…
Most modern businesses spend a lot of time thinking about digital touchpoints. Websites, email campaigns,…
While TikTok and Instagram battle for users’ attention with short vertical videos, Elon Musk’s social…
When you are looking to apply for a mortgage the one thing that most people…
Once you've memorized basic blackjack strategy, it's time to delve deeper into the game. Advanced…
Yoga is no longer just a physical practice. Yoga is popular as a lifestyle practice.…