Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
23-Apr-2025In Knockout.js, components are isolated by design — they each have their own view model and binding context. But sometimes, you'll want them to communicate, either to share data, trigger events, or sync state.
Let’s explore the most effective ways to handle component-to-component communication
Common Scenarios
Parent → Child (via
params)This is straightforward. You pass observables or functions to the child via
params.Child → Parent (via callback)
Pass a function (e.g.
onSave,onDelete) down to the child viaparams.Then the child just calls
params.onDelete()when needed.Sibling Components (via shared view model)
Define shared state outside the components and pass it down to both.
Use it in multiple components:
This lets components react to the same observable data.
Using a Pub/Sub (Custom Event Bus)
For more decoupled communication, use a simple event hub.
Now
senderandreceiverare independent, but still can talkSummary
params(observables/functions)subscribable)