Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is is possible to use same viewModel for multiple views? #226

Open
mrshawn191 opened this issue Jan 12, 2018 · 1 comment
Open

Is is possible to use same viewModel for multiple views? #226

mrshawn191 opened this issue Jan 12, 2018 · 1 comment

Comments

@mrshawn191
Copy link

<div data-bind="page: {id: 'xxx', title: 'xxx : User Settings', sourceOnShow: 'view/test.html', with: vm, afterShow: _.bind(vm.readDataById, vm) }"></div>


<div data-bind="page: {id: 'yyy', title: 'yyy : User Settings', sourceOnShow: 'view/test2.html', with: vm, afterShow: _.bind(vm.readDataById, vm) }"></div>

Im getting Uncaught ReferenceError: Unable to process binding "text: function (){return username }"

Problem only occurs when navigating from one page to another. During initial load both pages works ok.

@mw44118
Copy link

mw44118 commented Feb 8, 2018

First off, yes, I use the same viewmodel with multiple pages all the time.

Second, I don't think you need to use _.bind(vm.readDataById, vm); I think you can probably just do

afterShow: vm.readDataById

and that method will fire every time somebody hits that page.

The error you are getting, UncaughtReferenceError, is likely because inside your template HTML files, you're referencing some observable that is not in scope in that block. For example, maybe you're in a foreach loop, and the username observable lives on the parent, not on each element you are looping through.

Are you sure that a username observable lives on your vm object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants