Reputation: 343
Any ideas why this doesn't work for me? I'm using knockout 2.3.
<!-- ko if: vendorName() -->
<div>
<label for="vendorName" class="form-label bold">Name:</label>
<input name="vendorName" id="vendorName" type="text" class="" style="">
</div>
<!-- /ko -->
Here's the view-model
function SearchFieldViewModel() {
var self = this;
self.vendorName = ko.observable(false)
};
I've tried adding $root
and $parent
. I've tried vendorName()
, and just vendorName
. Nothing works. If I use standard data-binding on the div, that works just fine. I just can't get the containerless syntax to work, which I would prefer to use since I would like the div to be gone, not just what's inside the div.
Upvotes: 1
Views: 429
Reputation: 343
As Patrick Steele suggested, the comments were being stripped out. But not by the browser, but by JSF. Using this worked:
<h:outputText value="<!--" escape="false" /> ko if: vendorName <h:outputText value="-->" escape="false" />
....
....
<h:outputText value="<!--" escape="false" /> /ko <h:outputText value="-->" escape="false" />
Upvotes: 2
Reputation: 1905
It seems like the suggestions in the above comments would fix this for you
<!-- ko if: vendorName -->
<div>
<label for="vendorName" class="form-label bold">Name:</label>
<input type="text" name="vendorName" id="vendorName" data-bind="Name"/>
</div>
<!-- /ko -->
function SearchFieldViewModel() {
var self = this;
self.vendorName = ko.observable(false);
};
ko.applyBindings(new SearchFieldViewModel());
JSFiddle: http://jsfiddle.net/Pe9Kz/
Upvotes: 1