0

I have tried to create one simple code to change the bind value click on the button. when I load the page it's showing the message dev but when I click on the button its should show second but right now nothing happens when clicking on the button. is any ideas please share. I don't want to use setInterval.

HTML template file:

<h1 data-bind="text: getClock()"></h1>
<button type="button"
    click="action">
Click
</button>

JS file:

define([
    'uiComponent',
    'ko'
], function(Component, ko) {
    return Component.extend({
        clock: ko.observable("dev"),
        initialize: function () {
            this._super();
        },
        getClock: function () { 
            return this.clock;
        },
        action: function () {
            return this.clock = 'second';
        },
    });
});

1 Answer 1

1

try replacing

    action: function () {
        return this.clock = 'second';
    },

with

    action: function () {
        this.clock('second');
    },
1
  • Yes it's working. Thanks Marius ;) Aug 26, 2021 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.