Knockout component with custom element not working similar to component binding

Using knockoutjs; I have a custom component that works when used as a component binding, but doesn't work when used as a custom element.

See the fiddler here: http://jsfiddle.net/fmgbfthq/4/

Why does it work as expected when using component binding but not when used as a custom item? Shouldn't this work exactly the same?

<!-- params.loads is coming in as a function -->
<metric params="value: loads()"></metric>

<!-- params.loads is coming in as a value -->
<div data-bind="component: {
        name: 'metric',
        params: {
                value: loads()                   
        }
    }"></div>

      

+3


source to share


1 answer


The problem is that you keep overriding your value with ko.observable()

, and params.value

already is observable

.

Try this instead:



viewModel: function(params) {
    this.value = params.value;
    this.format = params.format;
},

      

See Fiddle

+1


source







All Articles