Uncheck checkbox on text input & clear text input when checkbox is checked

Viewed 1063

I have a search bar and check box as so:

<input type="text" placeholder="Search..." (keyup)="onKey()" [(ngModel)]="input">
<input type="checkbox" (click)="clearSearch()" [(ngModel)]="checkbox">View All

Whenever anyone types into the search bar I want the checkbox to become unchecked. Likewise, whenever anyone checks the checkbox, I want the search bar to be cleared.

I've tried the following:

export class App {
 checkbox = ['checked']
 clearSearch() { 
 this.input = '';
};
onKey() { 
 checkbox = ['unchecked']
}

But it obviously doesn't quite work.

Here is a plunker with the above code: https://plnkr.co/edit/uAYxswpoz18jlRUqAMn5?p=preview

Which is the best way to achieve this functionality?

Thanks!

2 Answers
Related