Is it possible to set a css property using an if condition with a regular variable instead of observables? Here's an example:
a.html file:
<span class="label" data-bind="text: isApproved, css: sampleglobalvar == true ? 'label-success' : 'label-important'"></span>
a.js file:
Edit:
define('durandal/app'],function(app) {
var a = function() {
sampleglobalvar = 'true'
};
}
However, I am encountering an error stating that 'sampleglobalvar' does not exist in the viewmodel. While I understand that observables should be used, I faced issues when switching between 'true' and 'false' values for observables:
For instance, using:
sampleglobalvar = ko.observable("");
and setting it like this:
if(//condition)
{
sampleglobalvar(true);
}
else
{
sampleglobalvar(false);
}
did not clear the observable properly, leading to unexpected results.
In conclusion, is there a way to utilize a regular JavaScript variable in the css data-bind property?