1

I have call one function on button click but right now its call on page load automatically. It should be call only when click on button. Knockout js

 define([
  'ko',
  'uiComponent'
], function (ko,Component) {
  'use strict';
   return Component.extend({
      firstname:ko.observable(),
      initialize:function(config){
          this._super();
      },
      getTest:function(){
        console.log('somi');
      }
   });  
});

HTML

<div data-bind="text: firstname"></div>
<button data-bind="click: getTest()">click me</button>

is any idea, please share.

1 Answer 1

1

got the solution:

Remove brackets from function and its worked :)

<button data-bind="click: getTest">click me</button>
1
  • what if you have to pass arguments to the function?
    – Zankar
    Aug 12, 2022 at 7:52

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.