-1

i want the functionality of writing in the input bar, and when i press the button, i want it to pass me to: "../search/". but instead i get "../search/undefined".

this is the code:

<input type="text" placeholder="Search" ng-model="searchedValue">

and:

<button [routerLink]="['/search', searchedValue]" routerLinkActive="is-active">search</button> 

what do i do wrong?

librogil
  • 91
  • 1
  • 7
  • First provide complete code. You are referring to `searchedValue` variable. `undefined` means that this variable is not in scope. Where do you define this variable? – muradm Jan 19 '21 at 16:17

2 Answers2

0

maybe you need to check

[(ngModel)]='searchedValue'

chedly
  • 11
0

ng-model binding is from AngularJS. In Angular2+ you need to bind to ngModel. You could also use two-way binding to have back and forth communication between the controller and template. Try the following

<input type="text" placeholder="Search" [(ngModel)]="searchedValue">
ruth
  • 29,535
  • 4
  • 30
  • 57
  • like i wrote to chedly here, with [(ngModel)] the page doesn't even load. so i guess i'm doing something even worse? – librogil Jan 19 '21 at 15:25