0

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.

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

6 Comments

It says SearchText.ToLowerCase() is not a function. But i can see he's passing [Object Object]. So probably because the search text when i click on the button isn't a string. How can i change it?
@John probably because {Name: Ragnar} should be {Name: 'Ragnar'}
you need to pass string instead of object just set ragnar
It still sends [object Object]
yeah it says 2 min. I'll do it. Thanks for the help!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.