In Magento 2 I try to get shipping method in this js file : vendor/magento/module-checkout/view/frontend/web/template/billing-address.html
I try this :
quote.shippingMethod()['method_code'];
And I have this error :
Uncaught TypeError: Cannot read property 'method_code' of null
But when I console.log(quote);
I can see shippingMethod method code exist:
Do you have any idea how can I get shipping method attributes here ?
Thank you
EDIT
My goal is to change data-bind in this file : /vendor/magento/module-checkout/view/frontend/web/template/billing-address.html
<fieldset class="fieldset" data-bind="visible: !isAddressDetailsVisible()">
In order that isAddressDetailsVisible()
method return false if current shipping method is "colissimo pickup".
Best Answer
Try a simple way:
Where quote is 'Magento_Checkout/js/model/quote'
Avoiding js error, try the following way:
[Update]
Add the following code in your js class inside initialize method. Ex. view/frontend/web/js/view/billing-address.js initialize