i have two view models and i want to pass value from one view model to another viewmodel. i have two viewmodels and two div i want to display another div on click of button whic
For this you can follow these
Viewmodels
function vm1(parent){
var self = this
self.parent = ko.observable(parent)
.
.
.
self.myfunction(data){
self.parent().pageParameters(data)
}
}
function vm2(parent){
var self = this
self.parent = ko.observable(parent)
.
.
.
self.myotherfunction(){
var othervmdata = self.parent().pageParameters()
.
.
}
}
function vm(){
var self = this
self.vm1 = ko.observable();
self.vm2 = ko.observable();
self.pageParameters = ko.observable
self.loadData = function(){
self.vm1(new vm1(this))
self.vm2(new vm1(this))
}
}
View
.
.
.
.
.
.
This way when you bind myfunction
to click binding parent model will have the data you want to pass then on the other view model you can access parent property pageParameters
.
For more details see my post.