How to programmatically set or clear a value in the Searchbar component


I am using the Searchbar component in ionic2, and I need to set a value in the searchbar when someone clicks a button. I tried setting the value directly in the bound model, but that doesn’t seem to work as it throws some exception like data was modified after it was checked. So how can I get the instance of Searchbar and set/clear it’s contents programmatically?


You wouldn’t touch the search bar for this.
Instead, you’d modify the ngModel value.


Yes I assumed that but as I mentioned, if I try to modify the model,like this.searchModel = "" , where on the template it is set as [(ngModel)] = "searchModel", I immediately get the exception as I mentioned in OP