dimanche 9 juillet 2017

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

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: http://ift.tt/2twrIKJ

Which is the best way to achieve this functionality?

Thanks!

Aucun commentaire:

Enregistrer un commentaire