With components, can I replace a custom tag entirely with the template content?

29 views
Skip to first unread message

frontend_dev

unread,
May 2, 2015, 10:11:24 AM5/2/15
to knock...@googlegroups.com
So I played around with components and I have to say I love it!

There is one little thing that bugs me a bit and that is that this introduces another DOM node I 'd like to spare (without adding a lot of overhead of course).

So I have this code in my global template:

<form-text params="vm: props.userFirstName"></form-text>

("props.userFirstName" is my viewmodel I inject in the component, instead of defining it directly)

And my component  definition looks like this:

ko.components.register('form-text', {
    viewModel: function (params) { return params.vm; },
    template: '<div data-bind="... uses vm ..."> ... </div>'
});


In the resulting DOM, I get this:

<form-text params="vm: props.userFirstName">
    <div data-bind="... uses vm ..."> ... </div>
</form-text>


Is it possible to replace the custom tag completely with the template contents so that the resulting DOM looks like this?

<div data-bind="... uses vm ..."> ... </div>

Reply all
Reply to author
Forward
0 new messages