-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
compose in a foreach loop #22
Comments
The problem is in knockout-composition.ts, getViewModelInstance Original /** internal: do not use */
getViewModelInstance(moduleId: string): Promise<any> {
let index: number = moduleId.lastIndexOf("/");
let fileName: string = moduleId.substr(index === -1 ? 0 : index + 1).toLowerCase();
return loadModule(moduleId, this.loader).then((result: any): any => {
if (typeof result !== 'function') {
// Try to find a property which name matches the filename of the module
let constructorPropName: string|null = getMatchingProperty(result, fileName);
if (constructorPropName) {
// Use function of property.
// This occurs if the constructor function is exported by the module.
result = result[constructorPropName];
} else {
// The module returns an instance.
return result;
}
}
return this.container.get(result);
});
} Modified /** internal: do not use */
getViewModelInstance(moduleId: string): Promise<any> {
let index: number = moduleId.lastIndexOf("/");
let fileName: string = moduleId.substr(index === -1 ? 0 : index + 1).toLowerCase();
return loadModule(moduleId, this.loader).then((result: any): any => {
if (typeof result !== 'function') {
// Try to find a property which name matches the filename of the module
let constructorPropName: string|null = getMatchingProperty(result, fileName);
if (constructorPropName) {
// Use function of property.
// This occurs if the constructor function is exported by the module.
result = result[constructorPropName];
} else {
// The module returns an instance.
return result;
}
}
return new result();
});
} getViewModelInstance must create a new instance of the class/viewmodel. Singleton looks ok (The module returns an instance). Fix: From return this.container.get(result); To return new result(); |
Thanks for your bugreport @mteinum. I registered the constructor function as |
@code-chris thanks for the patch. I have updated to 2.1.0 and it works excellent. |
Hi,
It looks like if you compose multiple elements, all views are bound to the last element.
example:
parent.html
parent.ts
child.html
child.ts
Console output
a
b
c
browser output
Text: c
Text: c
Text: c
Are there any workarounds for this?
The text was updated successfully, but these errors were encountered: