Question

If I add in checkout inside the component's template something like this: <a href="#" data-bind="click: myFunction()"></a> with a console.log('myFunction executed') in component's function 'myFunction', than it will log the message on page refresh.

I'm trying this on Magento 2.2.6.

This should not happen. Anyone knows why it does ?

I don't have other code that will trigger click event. I got this in onother component too. It seems like every click binding is executed on initialize or something.

Change bindings are not called on page refresh, just 'click'.

Était-ce utile?

La solution

Found the problem.

It should be:

<a href="#" data-bind="click: myFunction"></a>

or if it needs $parent context than:

<a href="#" data-bind="click: myFunction.bind($parent, parameter1, parameter2, ..)"></a>

Found the answear here: https://mage2.pro/t/topic/1937

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top