I have a custom component that passes an object to the viewmodel of that component. Al this using typescript. The object arrives in the constructor but it is wrapped in an anonymous object by knockout.
Is there a way to prevent this and just get the strongly typed value object?
In the constructor I get this:
Object { value: Order, $raw: Object }
I would like to have the value/Order immediately.
Here is my code:
index.html:
<div data-bind="foreach: Orders"/>
<my-component params="value: $data"></my-component>
</div>
component.html:
<span data-bind="text: Name"></span>
component.ts
ko.components.register('my-component', {
viewModel: ComponentVm,
template: component.html"
});
Component.ts:
class ComponentVm{
public Name:string;
constructor(order:Order){
this.Name = order.Name; //Problem here because of anonymous object
}
}
Order.ts:
Class Order {
public Name:string = "Bob";
constructor(){}
}
One solution would be:
class ComponentVm{
public Name:string;
constructor(anonymousObject:any){
let order = anonymousObject.value;
this.Name = order.Name;
}
}
But that is not really nice.