John
John

Reputation: 281

Angular search in model on button click

I have acustom pipe filter that allows me to search in my model the search text and i'm struggling to make it work on button press instead of user input. Right now i'm trying to do it like that:

<input [{ngModel}="SearchText" type="text">

and i create my data like this:

<tr *ngFor="let c for char | filter : SearchText">
 <td> {{c.Name}} </td>
</tr>

So this works.

And now i try to add something like this:

<button type="button" ng-click="searchText = {Name: Ragnar}">Ragnar</button>

And this doesn't work. I also tried:

<button type="button" [{ngModel}="SearchText">Ragnar</button>

But it doesn't seem to read Ragnar too. Any ideas?

Angular 4.

Upvotes: 0

Views: 1255

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

There are few mistakes

change

From

<input [{ngModel}="SearchText" type="text">

To

<input [(ngModel)]="SearchText" type="text">

and (click) instead of ng-click

<button type="button" (click)="searchText = {Name: 'Ragnar'}">Ragnar</button>

Upvotes: 2

Related Questions