Reputation: 395
I am trying to get back the value from the input field using knockoutjs. The input filed has the binded variable filter and event handler that will be used to filter an array. I would like to obtain the value from the input and console.log the value typed by the user. However, My knockout newbish and I haven't find much help in the docs.
HTML
<div class="col-lg-12">
<div class="input-group">
<input data-bind="textInput: filter, event:{keyup: filterList}">
<button class="input-group-addon btn btn-primary">Filter</button>
</div>
</div>
View Model
var viewModel = function() {
var self = this;
self.filter = ko.observable('');
self.locationList = ko.observableArray(model);
self.filterList = function(){
console.log( self.filter)
};
}
Upvotes: 0
Views: 38
Reputation: 115
To console log the value of self.filter you should just need to change
console.log( self.filter)
to console.log(self.filter())
Upvotes: 1