How to add class in ko template in magento2
-
26-02-2021 - |
Pregunta
I want to add class in ko template
In js:
define([
'jquery',
'ko',
'uiComponent',
'underscore',
'mage/translate',
'mage/storage',
'Magento_Checkout/js/model/url-builder',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/checkout-data'
], function ($, ko, Component, _, $t, storage, urlBuilder, customer, quote, checkoutData) {
'use strict';
return Component.extend({
errorMessage: ko.observable(false),
showElement: ko.observable(),
initialize: function () {
this._super();
this.showElement = this.resolveInitialVisibility();
return this;
},
resolveInitialVisibility: function () {
if (checkoutData.getInputFieldEmailValue() !== '') {
return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
}
return false;
}
});
}
);
I need to add disable class for <div class="col-md-12 pdl0">
if the showElement returns true.
How to do that
Thanks.
Solución
You can use like this:
<div class="col-md-12 pdl0" data-bind="css: {'disable': showElement} ">
or like this:
<div class="col-md-12 pdl0" data-bind="css: showElement ? 'disable' : ''">
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange